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

Block plugin machine name UX is flawed

$
0
0

Follow-up to: #1884762: Block forms should use #type => machine_name

Problem

  • +++ b/core/modules/block/lib/Drupal/block/BlockBase.php
    @@ -241,11 +241,15 @@ public function form($form, &$form_state) {
           '#description' => t('A unique name to save this block configuration. Must be alpha-numeric and be underscore separated.'),
    ...
    +        'replace_pattern' => '[^a-z0-9_.]+',

    @@ -419,12 +423,7 @@ public function blockForm($form, &$form_state) {
    +    if (!empty($form['machine_name']['#disabled'])) {
           $config_id = explode('.', $form_state['values']['machine_name']);
           $form_state['values']['machine_name'] = array_pop($config_id);
         }

    The #description is still incorrect and misleading though? It doesn't mention that a dot is allowed, and, that there's some special logic is going on for the dot.

    Speaking of, why do we allow the dot, if

    A) the code doesn't actually support multiple dots in the machine name?

    B) everything before the last dot is stripped off the machine_name value in the form validation handler (for existing blocks)?

    It looks like this could be vastly simplified, if

    1) the machine name prefix (before the dot) was moved into a separate #type 'value' in the form already

    2) the machine_name only ever contains the user-supplied machine_name

    3) the user-supplied machine_name cannot contain dots, thus, removing the custom replace_pattern entirely.


Viewing all articles
Browse latest Browse all 291123

Trending Articles



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