You are here

public function ExampleEntityExtraFieldInfoSubscribers::fieldInfo in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 examples/ExampleEntityExtraFieldInfoSubscribers.php \Drupal\hook_event_dispatcher\ExampleEntityExtraFieldInfoSubscribers::fieldInfo()

Entity extra field info.

Parameters

\Drupal\core_event_dispatcher\Event\Entity\EntityExtraFieldInfoEvent $event: The event.

File

examples/ExampleEntityExtraFieldInfoSubscribers.php, line 29

Class

ExampleEntityExtraFieldInfoSubscribers
Class ExampleEntityExtraFieldInfoSubscribers.

Namespace

Drupal\hook_event_dispatcher

Code

public function fieldInfo(EntityExtraFieldInfoEvent $event) : void {

  // Set the field info directly.
  $fieldInfo = [];
  $event
    ->setFieldInfo($fieldInfo);
  $entityType = 'node';
  $bundle = 'page';
  $fieldName = 'field_test';
  $testFieldInfo = [];

  // Add a single display info.
  $event
    ->addDisplayFieldInfo($entityType, $bundle, $fieldName, $testFieldInfo);

  // Add a single form info.
  $event
    ->addFormFieldInfo($entityType, $bundle, $fieldName, $testFieldInfo);
}