You are here

public function CustomTextComponent::render in Flexiform 8

Render the component in the form.

Overrides FormComponentInterface::render

File

src/Plugin/FormComponentType/CustomTextComponent.php, line 50

Class

CustomTextComponent
Component class for field widgets.

Namespace

Drupal\flexiform\Plugin\FormComponentType

Code

public function render(array &$form, FormStateInterface $form_state, RendererInterface $renderer) {
  $token_data = $token_options = [];
  $token_info = $this->token
    ->getInfo();
  foreach ($this
    ->getFormEntityManager()
    ->getContexts() as $namespace => $context) {

    /* @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $context
      ->getContextValue();
    if (!$entity) {
      continue;
    }
    if ($namespace == '') {
      $namespace = 'base_entity';
    }
    $token_type = $entity
      ->getEntityType()
      ->get('token_type') ?: (!empty($token_info['types'][$entity
      ->getEntityTypeId()]) ? $entity
      ->getEntityTypeId() : FALSE);
    if ($token_type) {
      $token_data[$namespace] = $entity;
      $token_options['alias'][$namespace] = $token_type;
    }
  }
  $element = [
    '#type' => 'processed_text',
    '#text' => $this->token
      ->replace($this->options['content'], $token_data, $token_options),
    '#format' => $this->options['format'],
    '#weight' => $this->options['weight'],
  ];
  $form[$this->name] = $element;
}