New answers tagged

0

The BlockContent class uses the RefinableDependentAccessTrait which has 2 methods that can be used to add/set access dependencies: RefinableDependentAccessTrait::addAccessDependencyAdds an access dependency into the existing access dependency. RefinableDependentAccessTrait::setAccessDependencySets the access dependency. If an access dependency is already ...


0

on visibility settings, choose two mode of visibility, for example: type of content, choose one content type you want your block to show on on page visibility, you choose hide for listed page, the type /desert/*/*


1

This is not a webform issue. The problem is that BigPipe is unable to lazily load the block. What happens if you disable this module? If you want to debug the module, server-side it is delivering the content for placeholders delayed at the end of the page (scroll down in the HTML source). Client-side this is then processed in javascript. Check if javascript ...


2

You can do it with hook_preprocess_HOOK and the all caps HOOK part refers to the array key in hook_theme(). /** * Implements hook_preprocess_HOOK(). */ function mytheme_preprocess_commerce_cart_block(&$variables) { // Adds a custom variable $variables['hello_world'] = 'Hello World'; } BTW, this hook can be used either in a custom theme or custom ...


2

If it's just classes you need, the modules mentioned in Joseph's answer should be enough. If you need to make more alterations and definitely need a custom template file, you can implement hook_theme_suggestions_HOOK(). Something like: function module_theme_suggestions_block(array $variables) { $suggestions = []; if ($variables['elements']['#...


2

There are several modules that allow you to add classes to blocks via admin, depending on where you're adding the blocks: If using Layout Builder: https://www.drupal.org/project/layout_builder_component_attributes If using Block Layout: https://www.drupal.org/project/block_classes


3

When you create a module to display a block this usually means you implement a block plugin. Then you can add the condition to the plugin directly: protected function blockAccess(AccountInterface $account) { $access = $this->languageManager->isMultilingual() ? AccessResult::allowed() : AccessResult::forbidden(); return $access->...


1

If a user doesn't have the admin permission for an entity type this doesn't mean you can't allow specific operations on specific existing entities. For example, content editors you gave permission to administer content are also allowed to update blocks of your custom block plugin: use Drupal\block\Entity\Block; use Drupal\Core\Access\AccessResult; use Drupal\...


0

Found the solution to this issue. You can have just one twig file, the custom block twig file, and access the fields inside the paragraphs. Move the paragraph variables to inside the for loop, and replace the variables like this: old code ["#paragraph"].field_paragraph_title.value new code item.entity.field_paragraph_title.value and replace the for ...


0

The count needs to be in the custom block's paragraph field twig, not the paragraph twig. In the field--field-hover-image-block.html.twig, this works: {% set count = 0 %} {% for item in items %} {% set count = items|length %} {% set figure_classes = [ 'hover-image-effect', 'image-count-' ~ count ] | sort | join(' ') | trim %} <...


1

or how can I do something in twig, like {% if region == 'sidebar-first' %} and just override book-tree.html.twig // Adds a region attribute to a block. function uswds_subtheme_preprocess_block(&$variables) { if (isset($variables["elements"]["#id"])) { $block_id = $variables["elements"]["#id"]; $block = \...


1

Using all of the help from @NoSssweat and I was able get this working: // Add a region variable to a block. function uswds_subtheme_preprocess_block(&$variables) { if (isset($variables["elements"]["#id"])) { $block_id = $variables["elements"]["#id"]; $block = \Drupal\block\Entity\Block::load($block_id); ...


1

Nice try, since this is a book and not menu, the process is similar, but not exactly the same. I was hoping you would figure it out. But anyways, here you go: /** * Implements hook_preprocess_HOOK(). * * Pass block region value to content so this can be used in * uswds_subtheme_theme_suggestions_menu_alter() since $variables['elements'] * is not ...


2

There is an abstaction layer between the storage of the block config and the block view building. Block configuration can be stored anywhere and doesn't necessarily have a machine name. You can however transfer the machine name to the block settings when you place a block in Block Layout: use Drupal\block\BlockInterface; /** * Implements ...


Top 50 recent answers are included