Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293129

Auto-generate machine_name for Views Blocks using [viewname]_[displayname] rather than forcing manual entry

$
0
0

Currently, users must type in a custom machine_name when placing a new Views block instance.

views-block-machine-name-manual.png

Normally, a block machine_name is generated from the label. This doesn't work for Views blocks since ViewsBlock:form() unsets this property. See: #1957276: Let users set the block instance title for Views blocks in the Block UI

Drupal should handle assigning the machine_name for the user, generating it based on the View name and the display that the block is using (ie: block_1).

Views sets up its own plugin portions of the block configuration form but assigning machine names is not handled by the plugin. This happens afterward, when the block system hardcodes this in BlockFormController:form()

...
/**
   * Overrides \Drupal\Core\Entity\EntityFormController::form().
   */
  public function form(array $form, array &$form_state) {
    $entity = $this->entity;
    $form['#tree'] = TRUE;
    $form['id'] = array(
      '#type' => 'value',
      '#value' => $entity->id(),
    );
    $form['settings'] = $entity->getPlugin()->form(array(), $form_state);

    $form['machine_name'] = array(
      '#type' => 'machine_name',
      '#title' => t('Machine name'),
      '#maxlength' => 64,
      '#description' => t('A unique name to save this block configuration. Must be alpha-numeric and be underscore separated.'),
      '#default_value' => $entity->id(),
      '#machine_name' => array(
        'exists' => 'block_load',
        'replace_pattern' => '[^a-z0-9_.]+',
        'source' => array('settings', 'label'),
      ),
      '#required' => TRUE,
      '#disabled' => !$entity->isNew(),
    );
...

Talking to xjm, effulgentsia and dawehner, we've determined a patch should provide a form_alter in views.module that gives Views this special ability to assign auto-generated machine name for its blocks.

AttachmentSizeStatusTest resultOperations
views-block-machine-name-manual.png77.49 KBIgnoredNoneNone

Viewing all articles
Browse latest Browse all 293129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>