class CheeseburgerMenuTrigger in Cheeseburger Menu 5.0.x
Provides a 'CheeseburgerMenu' block.
Plugin annotation
@Block(
id = "cheeseburger_menu_trigger",
admin_label = @Translation("Cheeseburger menu trigger")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, ContextAwarePluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait, ContextAwarePluginTrait
- class \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenuTrigger implements ContainerFactoryPluginInterface
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, ContextAwarePluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait, ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CheeseburgerMenuTrigger
File
- src/
Plugin/ Block/ CheeseburgerMenuTrigger.php, line 22
Namespace
Drupal\cheeseburger_menu\Plugin\BlockView source
class CheeseburgerMenuTrigger extends BlockBase implements ContainerFactoryPluginInterface {
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Breakpoint manager.
*
* @var \Drupal\breakpoint\BreakpointManagerInterface|null
*/
protected $breakPointManager;
/**
* Theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* Cheeseburger menu trigger constructor.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, ThemeManagerInterface $theme_manager, BreakpointManagerInterface $break_point_manager = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $config_factory;
$this->breakPointManager = $break_point_manager;
$this->themeManager = $theme_manager;
}
/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('config.factory'), $container
->get('theme.manager'), $container
->has('breakpoint.manager') ? $container
->get('breakpoint.manager') : NULL);
}
/**
* {@inheritDoc}
*/
public function defaultConfiguration() {
return [
'block_to_trigger' => NULL,
'breakpoints' => [],
'custom_media_query' => NULL,
] + parent::defaultConfiguration();
}
/**
* {@inheritDoc}
*/
public function calculateDependencies() {
$dependencies = [];
$block_to_trigger = $this->configuration['block_to_trigger'];
$cheeseburger_block = $this->entityTypeManager
->getStorage('block')
->load($block_to_trigger);
$dependencies['config'][] = $cheeseburger_block
->getConfigDependencyName();
return array_merge($dependencies, parent::calculateDependencies());
}
/**
* {@inheritDoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$conditions = [
'plugin' => 'cheeseburger_menu',
];
$form_object = $form_state
->getFormObject();
$theme = $this->configFactory
->get('system.theme')
->get('default');
if ($form_object && method_exists($form_object, 'getEntity')) {
$block = $form_object
->getEntity();
$theme = $block
->getTheme();
$conditions['theme'] = $block
->getTheme();
}
$block_options = array_map(function ($menu_item) {
return $menu_item
->label() . ' (' . $menu_item
->id() . ')';
}, $this->entityTypeManager
->getStorage('block')
->loadByProperties($conditions));
$form['block_to_trigger'] = [
'#type' => 'radios',
'#title' => $this
->t('Block to trigger'),
'#options' => $block_options,
'#default_value' => $this->configuration['block_to_trigger'],
'#required' => TRUE,
];
$breakpoints = [];
if ($this->breakPointManager) {
foreach ($this->breakPointManager
->getGroups() as $group_id => $group) {
$providers = $this->breakPointManager
->getGroupProviders($group_id);
if (isset($providers[$theme])) {
foreach ($this->breakPointManager
->getBreakpointsByGroup($group_id) as $breakpoint) {
$breakpoints[$breakpoint
->getMediaQuery()] = "{$breakpoint->getLabel()} ({$breakpoint->getMediaQuery()})";
}
}
}
}
$form['breakpoints'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Breakpoints'),
'#descriptions' => $this
->t('Choose breakpoints on which you want your trigger to appear'),
'#options' => $breakpoints,
'#default_value' => $this->configuration['breakpoints'],
'#access' => FALSE,
];
$form['custom_media_query'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom media query'),
'#description' => '<ul><li>' . $this
->t('Custom media query when trigger will not be displayed. Leave empty to show all the time.') . '</li><li>' . $this
->t('Example: @media_query', [
'@media_query' => 'all and (min-width: 500px)',
]) . '</li>',
'#default_value' => $this->configuration['custom_media_query'],
];
return $form;
}
/**
* {@inheritDoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['block_to_trigger'] = $form_state
->getValue('block_to_trigger');
$this->configuration['breakpoints'] = array_filter($form_state
->getValue('breakpoints'));
$this->configuration['custom_media_query'] = !$form_state
->isValueEmpty('custom_media_query') ? $form_state
->getValue('custom_media_query') : NULL;
parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritDoc}
*/
public function build() {
$block_id = 'block-' . str_replace('_', '-', $this->configuration['block_to_trigger']);
if ($this->themeManager
->getActiveTheme()
->getName() === 'glisseo') {
$block_id .= ', .block--' . str_replace('_', '-', $this->configuration['block_to_trigger']);
}
return [
'#theme' => 'cheeseburger_menu_trigger',
'#menu_id' => $block_id,
];
}
}
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 | 16 | |
BlockPluginTrait:: |
public | function | 13 | |
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. Aliased as: traitBuildConfigurationForm | |
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:: |
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 |
CheeseburgerMenuTrigger:: |
protected | property | Breakpoint manager. | |
CheeseburgerMenuTrigger:: |
protected | property | Config factory. | |
CheeseburgerMenuTrigger:: |
protected | property | Entity type manager service. | |
CheeseburgerMenuTrigger:: |
protected | property | Theme manager. | |
CheeseburgerMenuTrigger:: |
public | function |
Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface:: |
|
CheeseburgerMenuTrigger:: |
public | function |
Form constructor. Overrides BlockBase:: |
|
CheeseburgerMenuTrigger:: |
public | function |
Overrides BlockPluginTrait:: |
|
CheeseburgerMenuTrigger:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
CheeseburgerMenuTrigger:: |
public | function |
Overrides BlockPluginTrait:: |
|
CheeseburgerMenuTrigger:: |
public | function |
Most block plugins should not override this method. To add submission
handling for a specific block type, override BlockBase::blockSubmit(). Overrides BlockPluginTrait:: |
|
CheeseburgerMenuTrigger:: |
public | function |
Cheeseburger menu trigger constructor. Overrides BlockPluginTrait:: |
|
ContextAwarePluginAssignmentTrait:: |
protected | function | Builds a form element for assigning a context to a given slot. | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginTrait:: |
protected | property | The data objects representing the context of this plugin. | |
ContextAwarePluginTrait:: |
protected | property | Tracks whether the context has been initialized from configuration. | |
ContextAwarePluginTrait:: |
public | function | 9 | |
ContextAwarePluginTrait:: |
public | function | 7 | |
ContextAwarePluginTrait:: |
public | function | 4 | |
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
abstract protected | function | 1 | |
ContextAwarePluginTrait:: |
public | function | 1 | |
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
ContextAwarePluginTrait:: |
public | function | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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 plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginWithFormsTrait:: |
public | function | Implements \Drupal\Core\Plugin\PluginWithFormsInterface::getFormClass(). | |
PluginWithFormsTrait:: |
public | function | Implements \Drupal\Core\Plugin\PluginWithFormsInterface::hasFormClass(). | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |