id() == 'node' && $bundle === 'frontpage') { // \Drupal::logger('materio_home')->notice('bundle: '.$bundle); if ($entity_type->id() == 'node' && $bundle == 'programme') { $fields['computed_themes_references'] = BaseFieldDefinition::create('entity_reference') ->setName('computed_themes_references') ->setLabel(t('Computed Themes References')) ->setDescription(t('Computed Themes References.')) // // The Entity Type this field belongs to. ->setTargetEntityTypeId($entity_type->id()) // // The Entity Type bundle this field belongs to. ->setTargetBundle($bundle) ->setSetting('target_type', 'node') ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ->setComputed(TRUE) ->setRevisionable(FALSE) ->setTranslatable(FALSE) ->setDisplayConfigurable('view', TRUE) ->setDisplayOptions('view', [ 'label' => 'hidden', 'weight' => -5, ]) ->setClass(\Drupal\popsu_programme\Plugin\Field\FieldType\ComputedThemesReferences::class); $fields['computed_projets_references'] = BaseFieldDefinition::create('entity_reference') ->setName('computed_projets_references') ->setLabel(t('Computed Projets References')) ->setDescription(t('Computed Projets References.')) // // The Entity Type this field belongs to. ->setTargetEntityTypeId($entity_type->id()) // // The Entity Type bundle this field belongs to. ->setTargetBundle($bundle) ->setSetting('target_type', 'node') ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ->setComputed(TRUE) ->setRevisionable(FALSE) ->setTranslatable(FALSE) ->setDisplayConfigurable('view', TRUE) ->setDisplayOptions('view', [ 'label' => 'hidden', 'weight' => -5, ]) ->setClass(\Drupal\popsu_programme\Plugin\Field\FieldType\ComputedProjetsReferences::class); return $fields; } } /** * Implements hook_views_data_alter(). */ function popsu_programme_views_data_alter(array &$data) { if (isset($data['node'])) { // Add the computed_themes_reference field to Views. $data['node']['computed_themes_reference'] = [ 'title' => t('Computed Theme References'), 'field' => [ 'id' => 'views_computed_themes_reference', ], ]; // Add the computed_projets_reference field to Views. $data['node']['computed_projets_reference'] = [ 'title' => t('Computed Projets References'), 'field' => [ 'id' => 'views_computed_projets_reference', ], ]; } }