You are here

public function ExtraFieldTokenPlugin::build in Entity Extra Field 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/ExtraFieldType/ExtraFieldTokenPlugin.php \Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldTokenPlugin::build()

Build the render array of the extra field type contents.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity type the extra field is being attached too.

\Drupal\Core\Entity\Display\EntityDisplayInterface $display: The entity display the extra field is apart of.

Return value

array The extra field renderable array.

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides ExtraFieldTypePluginInterface::build

File

src/Plugin/ExtraFieldType/ExtraFieldTokenPlugin.php, line 91

Class

ExtraFieldTokenPlugin
Define extra field token plugin.

Namespace

Drupal\entity_extra_field\Plugin\ExtraFieldType

Code

public function build(EntityInterface $entity, EntityDisplayInterface $display) : array {
  $build = [];
  if ($entity instanceof ContentEntityInterface) {
    $token_value = $this
      ->getProcessedTokenValue($entity);
    switch ($this
      ->getTokenTextType()) {
      case 'textfield':
        $build = [
          '#plain_text' => $token_value,
        ];
        break;
      case 'text_format':
        $build = [
          '#type' => 'processed_text',
          '#text' => $token_value,
          '#format' => $this
            ->getTokenTextFormat(),
        ];
        break;
    }
  }
  return $build;
}