BlockCreationTrait::placeBlock() should explain visibility

Created on 27 March 2024, 3 months ago
Updated 28 March 2024, 3 months ago

Problem/Motivation

   *   The following defaults are provided:
   *   - label: Random string.
   *   - id: Random string.
   *   - region: 'sidebar_first'.
   *   - theme: The default theme.
   *   - visibility: Empty array.

What does an empty array mean for visilibity? Visible everywhere or nowhere? The docs should say.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Documentation 

Last updated about 7 hours ago

No maintainer
Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • Assigned to bmahesh03121
  • 🇮🇳India bmahesh03121

    Working on this

  • Status changed to Needs work 3 months ago
  • 🇮🇳India bmahesh03121
      /**
       * Creates a block instance based on default settings.
       *
       * @param string $plugin_id
       *   The plugin ID of the block type for this block instance.
       * @param array $settings
       *   (optional) An associative array of settings for the block entity.
       *   Override the defaults by specifying the key and value in the array, for
       *   example:
       *   @code
       *     $this->drupalPlaceBlock('system_powered_by_block', array(
       *       'label' => t('Hello, world!'),
       *     ));
       *   @endcode
       *   The following defaults are provided:
       *   - label: Random string.
       *   - id: Random string.
       <del>*   - region: 'sidebar_first'.</del>
       *   - region: 'content'.
       *   - theme: The default theme.
       *   - visibility: Empty array (block will be visible on all pages).
       *
       * @return \Drupal\block\Entity\Block
       *   The block entity.
       *
       * @todo
       *   Add support for creating content block instances.
       */
      protected function placeBlock($plugin_id, array $settings = []) {
        $config = \Drupal::configFactory();
        $settings += [
          'plugin' => $plugin_id,
          'region' => 'content',
          'id' => $this->randomMachineName(8),
          'theme' => $config->get('system.theme')->get('default'),
          'label' => $this->randomMachineName(8),
          'visibility' => [],
          'weight' => 0,
        ];
    

    @joachim looking at this, i found that the default value for region is

    sidebar_first

    , but in function definition its taking

    content

    as default region

    + will it be good idea to provide the example with few more settings like visibility, region, theme instead of just label.

Production build 0.69.0 2024