You are here

public function MachineName::prepare in YAML Form 8

Prepare an element to be rendered within a form.

Parameters

array $element: An element.

\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.

Overrides YamlFormElementBase::prepare

File

src/Plugin/YamlFormElement/MachineName.php, line 23

Class

MachineName
Provides a 'machine_name' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
  parent::prepare($element, $yamlform_submission);

  // Since all elements are place under the $form['elements'] we need to
  // prepend the 'element' container to the #machine_name source.
  if (isset($element['#machine_name']['source'])) {
    array_unshift($element['#machine_name']['source'], 'elements');
  }
  else {
    $element['#machine_name']['source'] = [
      'elements',
      'label',
    ];
  }

  // Set #exists callback to function that will always returns TRUE.
  // This will prevent error and arbitrary functions from being called.
  // @see \Drupal\Core\Render\Element\MachineName::validateMachineName.
  $element['#machine_name']['exists'] = [
    get_class($this),
    'exists',
  ];
}