Commit 4151a14e authored by Michael Nolan's avatar Michael Nolan

Initial Commit

parent 2062dd2e
Pipeline #5 canceled with stages
name: 'AJAX Dashboard'
type: module
description: 'Creates a means of producing simple, themable ajax dashboards'
core: 8.x
package: 'User Interface'
<?php
/**
* @file
* Contains ajax_dashboard.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function ajax_dashboard_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the ajax_dashboard module.
case 'help.page.ajax_dashboard':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Creates a means of producing simple, themable ajax dashboards') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function ajax_dashboard_theme() {
return [
'ajax_dashboard' => [
'render element' => 'children',
],
];
}
services:
plugin.manager.ajax_dashboard:
class: Drupal\ajax_dashboard\AJAXDashboardManager
arguments: ['@module_handler', '@cache.discovery']
plugin.manager.ajax_dashboard_section:
class: Drupal\ajax_dashboard\Plugin\AJAXDashboardSectionManager
parent: default_plugin_manager
#
# Ajax Dashboards
#
# Each top-level entry is a dashboard, which calls a list of plugin-based listings
#
ajax_dashboard_example_profile:
id: ajax_dashboard_example_profile
label: 'Profile example'
content:
example:
type: ajax_dashboard_example
constant:
type: ajax_dashboard_constant
label: 'Example of a Constant'
content: 'Test Content'
name: 'AJAX Dashboard Example'
type: module
description: 'Example Dashboard'
core: 8.x
package: 'Examples'
<?php
/**
* @file
*/
/**
* Implements hook_entity_extra_field_info() to add the view fields to relevant entities
*/
function ajax_dashboard_example_entity_extra_field_info() {
$ret = array();
$ret['user']['user']['display']['ajax_dashboard_example'] = [
'label' => t('AJAX Dashboard Example'),
'description' => t('AJAX Dashboard Example'),
'weight' => 10,
];
return $ret;
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function ajax_dashboard_example_user_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
$dashboard = \Drupal\ajax_dashboard\AJAXDashboard::getDashboard('ajax_dashboard_example_profile');
$build['ajax_dashboard_example'] = $dashboard;
}
\ No newline at end of file
{
"name": "ajax_dashboard",
"type": "drupal-module",
"description": "Creates a means of producing simple, themable ajax dashboards",
"keywords": [
],
"homepage": "https://www.drupal.org/project/ajax_dashboard",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/ajax_dashboard",
"source": "http://cgit.drupalcode.org/ajax_dashboard",
},
}
<?php
namespace Drupal\ajax_dashboard;
use Drupal\Core\Discovery\YamlDiscovery;
class AJAXDashboard {
public static function getDashboard($dashboard_id) {
$dashboard_manager = \Drupal::service('plugin.manager.ajax_dashboard');
$dashboard_section_manager = \Drupal::service('plugin.manager.ajax_dashboard_section');
/** @var $manager AJAXDashboardManagerInterface */
$dashboards = $manager->getDefinitions();
if (isset($dashboards[$dashboard_id])) {
// TODO digest the content, and use the section manager here.
}
else {
return ['#markup' => 'hi'];
}
}
}
\ No newline at end of file
<?php
namespace Drupal\ajax_dashboard;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
/**
* Provides the default ajax_dashboard manager.
*/
class AJAXDashboardManager extends DefaultPluginManager implements AJAXDashboardManagerInterface {
/**
* Provides default values for all ajax_dashboard plugins.
*
* @var array
*/
protected $defaults = [
// Add required and optional plugin properties.
'id' => '',
'label' => '',
];
/**
* Constructs a new AJAXDashboardManager object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
*/
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
// Add more services as required.
$this->moduleHandler = $module_handler;
$this->setCacheBackend($cache_backend, 'ajax_dashboard', ['ajax_dashboard']);
}
/**
* {@inheritdoc}
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('ajax_dashboard', $this->moduleHandler->getModuleDirectories());
$this->discovery->addTranslatableProperty('label', 'label_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
}
return $this->discovery;
}
/**
* {@inheritdoc}
*/
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
// You can add validation of the plugin definition here.
if (empty($definition['id'])) {
throw new PluginException(sprintf('Example plugin property (%s) definition "is" is required.', $plugin_id));
}
}
// Add other methods here as defined in the AJAXDashboardManagerInterface.
}
<?php
namespace Drupal\ajax_dashboard;
use Drupal\Component\Plugin\PluginManagerInterface;
/**
* Defines an interface for ajax_dashboard managers.
*/
interface AJAXDashboardManagerInterface extends PluginManagerInterface {
// Add getters and other public methods for ajax_dashboard managers.
}
<?php
namespace Drupal\ajax_dashboard\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a AJAX Dashboard Section item annotation object.
*
* @see \Drupal\ajax_dashboard\Plugin\AJAXDashboardSectionManager
* @see plugin_api
*
* @Annotation
*/
class AJAXDashboardSection extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The label of the plugin.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;
}
<?php
namespace Drupal\ajax_dashboard\Plugin;
use Drupal\Component\Plugin\PluginBase;
/**
* Base class for AJAX Dashboard Section plugins.
*/
abstract class AJAXDashboardSectionBase extends PluginBase implements AJAXDashboardSectionInterface {
// Add common methods and abstract methods for your plugin type here.
}
<?php
namespace Drupal\ajax_dashboard\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* Defines an interface for AJAX Dashboard Section plugins.
*/
interface AJAXDashboardSectionInterface extends PluginInspectionInterface {
// Add get/set methods for your plugin type here.
}
<?php
namespace Drupal\ajax_dashboard\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Provides the AJAX Dashboard Section plugin manager.
*/
class AJAXDashboardSectionManager extends DefaultPluginManager {
/**
* Constructs a new AJAXDashboardSectionManager object.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/AJAXDashboardSection', $namespaces, $module_handler, 'Drupal\ajax_dashboard\Plugin\AJAXDashboardSectionInterface', 'Drupal\ajax_dashboard\Annotation\AJAXDashboardSection');
$this->alterInfo('ajax_dashboard_ajax_dashboard_section_info');
$this->setCacheBackend($cache_backend, 'ajax_dashboard_ajax_dashboard_section_plugins');
}
}
<!-- Add you custom twig html here -->
<?php
namespace Drupal\Tests\ajax_dashboard\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group ajax_dashboard
*/
class LoadTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['ajax_dashboard'];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}
/**
* Tests that the home page loads with a 200 response.
*/
public function testLoad() {
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertSession()->statusCodeEquals(200);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment