https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Ma...

Below YAML markup is not working as expected...

label:
  '#type': textfield
  '#title': 'Label'
machine_name:
  '#type': machine_name
  '#title': 'Machine name'
  '#machine_name':
    source: label

and throws...

Fatal error: Cannot use string offset as an array in /private/var/www/sites/d8_dev/core/lib/Drupal/Core/Form/FormBuilder.php on line 1011

Comments

jrockowitz created an issue. See original summary.

  • jrockowitz committed b014a66 on 8.x-1.x
    Issue #2693871: Add machine_name element example
    
jrockowitz’s picture

Status: Active » Fixed

There is now the below working example for a machine name element with a label included in the 'Inputs: Examples'

# https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!MachineName.php/8
machine_name_label:
  '#type': textfield
  '#title': 'Label with machine name'
  '#id': 'source'
machine_name:
  '#type': machine_name
  '#title': 'Machine name'
  '#machine_name':
     source:
      - machine_name_label

Please note, the $form['machine_name']['#machine_name']['source'] array must match the parent element names.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.