Currently, users must type in a custom machine_name when placing a new Views block instance.
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.
Attachment | Size | Status | Test result | Operations |
---|---|---|---|---|
views-block-machine-name-manual.png | 77.49 KB | Ignored | None | None |