You are here

public function YamlFormMessage::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 YamlFormMarkupBase::prepare

File

src/Plugin/YamlFormElement/YamlFormMessage.php, line 47

Class

YamlFormMessage
Provides a 'yamlform_message' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
  parent::prepare($element, $yamlform_submission);
  if (!empty($element['#message_storage']) && empty($element['#message_id'])) {

    // Use
    // [yamlform:id]--[source_entity:type]-[source_entity:id]--[element:key]
    // as the message id.
    $id = [];
    if ($yamlform = $yamlform_submission
      ->getYamlForm()) {
      $id[] = $yamlform
        ->id();
    }
    if ($source_entity = $yamlform_submission
      ->getSourceEntity()) {
      $id[] = $source_entity
        ->getEntityTypeId() . '-' . $source_entity
        ->id();
    }
    $id[] = $element['#yamlform_key'];
    $element['#message_id'] = implode('--', $id);
  }
}