Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
124
core/modules/toolbar/src/Element/Toolbar.php
Normal file
124
core/modules/toolbar/src/Element/Toolbar.php
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\toolbar\Element\Toolbar.
|
||||
*/
|
||||
|
||||
namespace Drupal\toolbar\Element;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Render\Element\RenderElement;
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Provides a render element for the default Drupal toolbar.
|
||||
*
|
||||
* @RenderElement("toolbar")
|
||||
*/
|
||||
class Toolbar extends RenderElement {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInfo() {
|
||||
$class = get_class($this);
|
||||
return array(
|
||||
'#pre_render' => array(
|
||||
array($class, 'preRenderToolbar'),
|
||||
),
|
||||
'#theme' => 'toolbar',
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
'toolbar/toolbar',
|
||||
),
|
||||
),
|
||||
// Metadata for the toolbar wrapping element.
|
||||
'#attributes' => array(
|
||||
// The id cannot be simply "toolbar" or it will clash with the
|
||||
// simpletest tests listing which produces a checkbox with attribute
|
||||
// id="toolbar".
|
||||
'id' => 'toolbar-administration',
|
||||
'role' => 'group',
|
||||
'aria-label' => $this->t('Site administration toolbar'),
|
||||
),
|
||||
// Metadata for the administration bar.
|
||||
'#bar' => array(
|
||||
'#heading' => $this->t('Toolbar items'),
|
||||
'#attributes' => array(
|
||||
'id' => 'toolbar-bar',
|
||||
'role' => 'navigation',
|
||||
'aria-label' => $this->t('Toolbar items'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Toolbar as a structured array ready for drupal_render().
|
||||
*
|
||||
* Since building the toolbar takes some time, it is done just prior to
|
||||
* rendering to ensure that it is built only if it will be displayed.
|
||||
*
|
||||
* @param array $element
|
||||
* A renderable array.
|
||||
*
|
||||
* @return array
|
||||
* A renderable array.
|
||||
*
|
||||
* @see toolbar_page_top().
|
||||
*/
|
||||
public static function preRenderToolbar($element) {
|
||||
// Get the configured breakpoints to switch from vertical to horizontal
|
||||
// toolbar presentation.
|
||||
$breakpoints = static::breakpointManager()->getBreakpointsByGroup('toolbar');
|
||||
if (!empty($breakpoints)) {
|
||||
$media_queries = array();
|
||||
foreach ($breakpoints as $id => $breakpoint) {
|
||||
$media_queries[$id] = $breakpoint->getMediaQuery();
|
||||
}
|
||||
|
||||
$element['#attached']['drupalSettings']['toolbar']['breakpoints'] = $media_queries;
|
||||
}
|
||||
|
||||
$module_handler = static::moduleHandler();
|
||||
// Get toolbar items from all modules that implement hook_toolbar().
|
||||
$items = $module_handler->invokeAll('toolbar');
|
||||
// Allow for altering of hook_toolbar().
|
||||
$module_handler->alter('toolbar', $items);
|
||||
// Sort the children.
|
||||
uasort($items, array('\Drupal\Component\Utility\SortArray', 'sortByWeightProperty'));
|
||||
|
||||
// Merge in the original toolbar values.
|
||||
$element = array_merge($element, $items);
|
||||
|
||||
// Assign each item a unique ID, based on its key.
|
||||
foreach (Element::children($element) as $key) {
|
||||
$element[$key]['#id'] = Html::getId('toolbar-item-' . $key);
|
||||
}
|
||||
|
||||
// Render the children.
|
||||
$element['#children'] = drupal_render_children($element);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the breakpoint manager.
|
||||
*
|
||||
* @return \Drupal\breakpoint\BreakpointManagerInterface
|
||||
*/
|
||||
protected static function breakpointManager() {
|
||||
return \Drupal::service('breakpoint.manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the module handler.
|
||||
*
|
||||
* @return \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected static function moduleHandler() {
|
||||
return \Drupal::moduleHandler();
|
||||
}
|
||||
|
||||
}
|
92
core/modules/toolbar/src/Element/ToolbarItem.php
Normal file
92
core/modules/toolbar/src/Element/ToolbarItem.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\toolbar\Element\ToolbarItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\toolbar\Element;
|
||||
|
||||
use Drupal\Core\Render\Element\RenderElement;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Provides a toolbar item that is wrapped in markup for common styling.
|
||||
*
|
||||
* The 'tray' property contains a renderable array.
|
||||
*
|
||||
* @RenderElement("toolbar_item")
|
||||
*/
|
||||
class ToolbarItem extends RenderElement {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInfo() {
|
||||
$class = get_class($this);
|
||||
return array(
|
||||
'#pre_render' => array(
|
||||
array($class, 'preRenderToolbarItem'),
|
||||
),
|
||||
'tab' => array(
|
||||
'#type' => 'link',
|
||||
'#title' => NULL,
|
||||
'#url' => Url::fromRoute('<front>'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides markup for associating a tray trigger with a tray element.
|
||||
*
|
||||
* A tray is a responsive container that wraps renderable content. Trays
|
||||
* present content well on small and large screens alike.
|
||||
*
|
||||
* @param array $element
|
||||
* A renderable array.
|
||||
*
|
||||
* @return array
|
||||
* A renderable array.
|
||||
*/
|
||||
public static function preRenderToolbarItem($element) {
|
||||
$id = $element['#id'];
|
||||
|
||||
// Provide attributes for a toolbar item.
|
||||
$attributes = array(
|
||||
'id' => $id,
|
||||
);
|
||||
|
||||
// If tray content is present, markup the tray and its associated trigger.
|
||||
if (!empty($element['tray'])) {
|
||||
// Provide attributes necessary for trays.
|
||||
$attributes += array(
|
||||
'data-toolbar-tray' => $id . '-tray',
|
||||
'aria-owns' => $id . '-tray',
|
||||
'role' => 'button',
|
||||
'aria-pressed' => 'false',
|
||||
);
|
||||
|
||||
// Merge in module-provided attributes.
|
||||
$element['tab'] += array('#attributes' => array());
|
||||
$element['tab']['#attributes'] += $attributes;
|
||||
$element['tab']['#attributes']['class'][] = 'trigger';
|
||||
|
||||
// Provide attributes for the tray theme wrapper.
|
||||
$attributes = array(
|
||||
'id' => $id . '-tray',
|
||||
'data-toolbar-tray' => $id . '-tray',
|
||||
);
|
||||
// Merge in module-provided attributes.
|
||||
if (!isset($element['tray']['#wrapper_attributes'])) {
|
||||
$element['tray']['#wrapper_attributes'] = array();
|
||||
}
|
||||
$element['tray']['#wrapper_attributes'] += $attributes;
|
||||
$element['tray']['#wrapper_attributes']['class'][] = 'toolbar-tray';
|
||||
}
|
||||
|
||||
$element['tab']['#attributes']['class'][] = 'toolbar-item';
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue