public function MachineName::prepare in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElement/MachineName.php \Drupal\webform\Plugin\WebformElement\MachineName::prepare()
Prepare an element to be rendered within a webform.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission. Webform submission is optional since it is not used by composite sub elements.
Overrides WebformElementBase::prepare
See also
\Drupal\webform\Element\WebformCompositeBase::processWebformComposite
File
- src/
Plugin/ WebformElement/ MachineName.php, line 39
Class
- MachineName
- Provides a 'machine_name' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::prepare($element, $webform_submission);
// Since all elements are placed 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',
];
}