class UltimenuBlock in Ultimenu 8.2
Same name in this branch
- 8.2 src/Plugin/Derivative/UltimenuBlock.php \Drupal\ultimenu\Plugin\Derivative\UltimenuBlock
- 8.2 src/Plugin/Block/UltimenuBlock.php \Drupal\ultimenu\Plugin\Block\UltimenuBlock
Same name and namespace in other branches
- 8 src/Plugin/Block/UltimenuBlock.php \Drupal\ultimenu\Plugin\Block\UltimenuBlock
Provides an 'Ultimenu' block.
Plugin annotation
@Block(
id = "ultimenu_block",
admin_label = @Translation("Ultimenu block"),
category = @Translation("Ultimenu"),
deriver = "Drupal\ultimenu\Plugin\Derivative\UltimenuBlock",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait
- class \Drupal\ultimenu\Plugin\Block\UltimenuBlock implements ContainerFactoryPluginInterface
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
Expanded class hierarchy of UltimenuBlock
File
- src/
Plugin/ Block/ UltimenuBlock.php, line 25
Namespace
Drupal\ultimenu\Plugin\BlockView source
class UltimenuBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The library discovery service.
*
* @var \Drupal\Core\Asset\LibraryDiscoveryInterface
*/
protected $libraryDiscovery;
/**
* The Ultimenu manager service.
*
* @var \Drupal\ultimenu\UltimenuManagerInterface
*/
protected $ultimenuManager;
/**
* The Ultimenu skin service.
*
* @var \Drupal\ultimenu\UltimenuSkinInterface
*/
protected $ultimenuSkin;
/**
* Constructs an UltimenuBlock object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The ultimenu manager.
* @param \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery
* The ultimenu manager.
* @param \Drupal\ultimenu\UltimenuManagerInterface $ultimenu_manager
* The ultimenu manager.
* @param \Drupal\ultimenu\UltimenuSkinInterface $ultimenu_skin
* The ultimenu skin service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user, LibraryDiscoveryInterface $library_discovery, UltimenuManagerInterface $ultimenu_manager, UltimenuSkinInterface $ultimenu_skin) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->libraryDiscovery = $library_discovery;
$this->ultimenuManager = $ultimenu_manager;
$this->ultimenuSkin = $ultimenu_skin;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('library.discovery'), $container
->get('ultimenu.manager'), $container
->get('ultimenu.skin'));
}
/**
* {@inheritdoc}
*/
public function delta() {
// Derivatives are prefixed with 'ultimenu-', e.g.: ultimenu-main.
$id = $this
->getDerivativeId();
return substr($id, 9);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'ajaxify' => FALSE,
'regions' => [],
'skin' => 'module|ultimenu--dark',
'submenu' => FALSE,
'orientation' => 'ultimenu--htb',
'submenu_position' => '',
'canvas_off' => '#header',
'canvas_on' => '#main-wrapper, .featured-top, .site-footer',
'canvas_skin' => 'scalein',
];
}
/**
* Overrides \Drupal\block\BlockBase::blockForm().
*/
public function blockForm($form, FormStateInterface $form_state) {
if ($this->currentUser
->hasPermission('administer ultimenu')) {
$ultimenu_admin = Url::fromRoute('ultimenu.settings')
->toString();
$form['ajaxify'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Ajaxify'),
'#default_value' => isset($this->configuration['ajaxify']) ? $this->configuration['ajaxify'] : FALSE,
'#description' => $this
->t('Check to load ultimenu region contents using AJAX. Only makes sense for massive contents.'),
];
// @todo all: $regions = (array) $this->ultimenuManager->getSetting('regions');
$regions = $this->ultimenuManager
->getRegionsByMenu($this
->delta());
$states['visible'][':input[name="settings[ajaxify]"]'] = [
'checked' => TRUE,
];
$form['regions'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Ajaxifed regions'),
'#options' => $regions,
'#default_value' => isset($this->configuration['regions']) ? array_values((array) $this->configuration['regions']) : [],
'#description' => $this
->t('Check which regions should be ajaxified, leaving those unchecked as non-ajaxed regions. Be sure to enable the regions at <a href=":url">Ultimenu admin</a>.', [
':url' => $ultimenu_admin,
]),
'#states' => $states,
];
$form['skin'] = [
'#type' => 'select',
'#title' => $this
->t('Ultimenu skin'),
'#default_value' => $this->configuration['skin'],
'#options' => $this->ultimenuSkin
->loadMultiple(),
'#empty_option' => $this
->t('- None -'),
'#description' => $this
->t('Choose the skin for this block. You can supply custom skins at <a href=":ultimenu_settings" target="_blank">Ultimenu settings</a>. The skin can be made specific to this block using the proper class by each menu name. Be sure to <a href=":clear" target="_blank">clear the cache</a> if trouble to see the new skin applied.', [
':ultimenu_settings' => $ultimenu_admin,
':clear' => Url::fromRoute('system.performance_settings')
->toString(),
]),
];
$form['orientation'] = [
'#type' => 'select',
'#title' => $this
->t('Flyout orientation'),
'#default_value' => $this->configuration['orientation'],
'#options' => [
'ultimenu--htb' => $this
->t('Horizontal to bottom'),
'ultimenu--htt' => $this
->t('Horizontal to top'),
'ultimenu--vtl' => $this
->t('Vertical to left'),
'ultimenu--vtr' => $this
->t('Vertical to right'),
],
'#description' => $this
->t('Choose the orientation of the flyout, depending on the placement. At sidebar left, <strong>Vertical to right</strong>. At header, <strong>Horizontal to bottom</strong>. At footer, <strong>Horizontal to top</strong>'),
];
$form['submenu'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Render submenu'),
'#default_value' => $this->configuration['submenu'],
'#description' => $this
->t('Render the relevant submenus inside the Ultimenu region without using Block admin, and independent from blocks. Alternatively use core Menu level option with regular menu block when core supports the "Fixed parent item", see <a href=":url" target="_blank">#2631468</a>. <br /><strong>Important!</strong> Be sure to check "<strong>Show as expanded</strong>" at the parent menu item edit page as needed, otherwise no submenus will be rendered.', [
':url' => 'https://www.drupal.org/node/2631468',
]),
];
$form['submenu_position'] = [
'#type' => 'select',
'#title' => $this
->t('Submenu position'),
'#options' => [
'bottom' => $this
->t('Bottom'),
'top' => $this
->t('Top'),
],
'#empty_option' => $this
->t('- None -'),
'#default_value' => $this->configuration['submenu_position'],
'#description' => $this
->t('Choose where to place the submenu, either before or after existing blocks. Default to Top.'),
];
if ($this->configuration['id'] == 'ultimenu_block:ultimenu-main') {
$form['canvas_off'] = [
'#type' => 'textfield',
'#title' => $this
->t('Off-canvas element'),
'#default_value' => $this->configuration['canvas_off'],
'#description' => $this
->t('Valid CSS selector for the off-canvas element. Only one can exist, for Bartik, e.g.: <code>#header</code> or <code>.region-primary-menu</code> (not good, just works). But not both.'),
];
$form['canvas_on'] = [
'#type' => 'textfield',
'#title' => $this
->t('On-canvas element'),
'#default_value' => $this->configuration['canvas_on'],
'#description' => $this
->t('Valid CSS selector for the on-canvas element. Can be multiple, for Bartik, e.g.: <code>#main-wrapper, .highlighted, .featured-top, .site-footer</code> <br>Visit <b>/admin/help/ultimenu</b> under <b>STYLING</b> section for details.'),
];
$skins = $this->ultimenuSkin
->getOffCanvasSkins();
$form['canvas_skin'] = [
'#type' => 'select',
'#title' => $this
->t('Off-canvas skin'),
'#options' => array_combine($skins, $skins),
'#default_value' => $this->configuration['canvas_skin'],
'#description' => $this
->t('The off-canvas skin. Note the name oldies is meant for old browsers up, but not as smoother. Consider Modernizr.js to support old browsers with advanced transform effects. More custom works are required as usual.'),
];
}
}
return $form;
}
/**
* Overrides \Drupal\block\BlockBase::blockSubmit().
*/
public function blockSubmit($form, FormStateInterface $form_state) {
foreach (array_keys($this
->defaultConfiguration()) as $key) {
$value = $form_state
->getValue($key);
$this->configuration[$key] = $key == 'regions' ? array_filter($value) : $value;
}
// Invalidate the library discovery cache to update the new skin discovery.
$this->ultimenuSkin
->clearCachedDefinitions();
$this->libraryDiscovery
->clearCachedDefinitions();
}
/**
* {@inheritdoc}
*/
public function build() {
$menu_name = $this
->delta();
$skin = $this->configuration['skin'];
$provider = '';
$skin_name = '';
$skin_basename = '';
// Load the specified block skin.
if (!empty($skin)) {
$skin_css_path = $this->ultimenuSkin
->getPath($skin);
$skin_basename = $this->ultimenuSkin
->getName($skin_css_path);
// Fetch the skin file name from the setting.
list($provider, $skin_name) = array_pad(array_map('trim', explode("|", $skin, 2)), 2, NULL);
}
// Provide the settings for further process.
$build['config'] = [
'bid' => $this
->getDerivativeId(),
'menu_name' => $menu_name,
'regions' => empty($this->configuration['regions']) ? [] : array_filter($this->configuration['regions']),
'skin_name' => $skin_name,
'skin_provider' => $provider,
'skin_basename' => $skin_basename,
] + $this->configuration;
return $this->ultimenuManager
->build($build);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockPluginInterface:: |
constant | Indicates the block label (title) should be displayed to end users. | ||
BlockPluginTrait:: |
protected | property | The transliteration service. | |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
protected | function | Returns generic default configuration for block plugins. | |
BlockPluginTrait:: |
protected | function | Indicates whether the block should be shown. | 16 |
BlockPluginTrait:: |
public | function | 3 | |
BlockPluginTrait:: |
public | function | Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements. | 2 |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | 1 | |
BlockPluginTrait:: |
public | function | 1 | |
BlockPluginTrait:: |
public | function | 3 | |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | Sets the transliteration service. | |
BlockPluginTrait:: |
public | function | Most block plugins should not override this method. To add submission handling for a specific block type, override BlockBase::blockSubmit(). | |
BlockPluginTrait:: |
protected | function | Wraps the transliteration service. | |
BlockPluginTrait:: |
public | function | Most block plugins should not override this method. To add validation for a specific block type, override BlockBase::blockValidate(). | 1 |
ContextAwarePluginAssignmentTrait:: |
protected | function | Builds a form element for assigning a context to a given slot. | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginBase:: |
protected | property | The data objects representing the context of this plugin. | |
ContextAwarePluginBase:: |
private | property | Data objects representing the contexts passed in the plugin configuration. | |
ContextAwarePluginBase:: |
protected | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
9 |
ContextAwarePluginBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
7 |
ContextAwarePluginBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
4 |
ContextAwarePluginBase:: |
public | function |
This code is identical to the Component in order to pick up a different
Context class. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Gets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the value for a defined context. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the values for all defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Set a context on this plugin. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Sets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Sets the value for a defined context. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Validates the set values for the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function | Implements magic __get() method. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginWithFormsTrait:: |
public | function | ||
PluginWithFormsTrait:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |
UltimenuBlock:: |
protected | property | The current user. | |
UltimenuBlock:: |
protected | property | The library discovery service. | |
UltimenuBlock:: |
protected | property | The Ultimenu manager service. | |
UltimenuBlock:: |
protected | property | The Ultimenu skin service. | |
UltimenuBlock:: |
public | function |
Overrides \Drupal\block\BlockBase::blockForm(). Overrides BlockPluginTrait:: |
|
UltimenuBlock:: |
public | function |
Overrides \Drupal\block\BlockBase::blockSubmit(). Overrides BlockPluginTrait:: |
|
UltimenuBlock:: |
public | function |
Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface:: |
|
UltimenuBlock:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
UltimenuBlock:: |
public | function |
Overrides BlockPluginTrait:: |
|
UltimenuBlock:: |
public | function | ||
UltimenuBlock:: |
public | function |
Constructs an UltimenuBlock object. Overrides BlockPluginTrait:: |