BlockCreationTrait::placeBlock() should explain visibility

Created on 27 March 2024, 12 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

Active

Version

11.0 🔥

Component
Documentation 

Last updated 4 days 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

Merge Requests

Comments & Activities

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

    Working on this

  • Status changed to Needs work 12 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.

  • 🇬🇧United Kingdom jacobupal Leeds
  • 🇬🇧United Kingdom jacobupal Leeds

    Updated the proposed resolution with regards to providing more settings.

    The changed the snippet is describing the default values not possible options.

  • 🇬🇧United Kingdom jacobupal Leeds
  • Pipeline finished with Failed
    5 months ago
    Total: 3353s
    #292981
  • 🇬🇧United Kingdom ChrisDarke London

    Hi bmahesh03121, please do not assign core issues to yourself, these should just be commented on, with something similar to "I am working on this issue for the next week".

    Also please try to not do updates on issues that are marked as reserved for Mentored Contribution, thanks!

  • Issue was unassigned.
  • 🇧🇷Brazil brandonlira

    Status update / Question: It looks like the docblock has been updated to address the visibility and region defaults. Is there anything else that needs to be done for this issue? If not, I can help test or review the current changes.

    Thanks!

  • 🇬🇧United Kingdom joachim

    MR looks good. Test failures are unrelated JS issues.

  • 🇮🇳India Sivaji_Ganesh_Jojodae Chennai

    On a related note, shouldn't we use wildcard /* instead of empty array [] to indicate the global visibility to be inline with the page visibility settings?

  • First commit to issue fork.
    • nod_ committed 4dcbb647 on 11.x
      Issue #3436435 by bmahesh03121, joachim, jacobupal: BlockCreationTrait::...
  • 🇫🇷France nod_ Lille

    Committed 4dcbb64 and pushed to 11.x. Thanks!

  • Pipeline finished with Failed
    4 days ago
    Total: 456s
    #440534
Production build 0.71.5 2024