getFieldMapByFieldType example



    $entity_type->getClass()->willReturn($entity_class)->shouldBeCalled();
    $entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode'])->shouldBeCalled();
    $entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE)->shouldBeCalled();
    $entity_type->isTranslatable()->shouldBeCalled();
    $entity_type->isRevisionable()->shouldBeCalled();
    $entity_type->getProvider()->shouldBeCalled();

    $override_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE)->shouldBeCalled();

    $integerFields = $this->entityFieldManager->getFieldMapByFieldType('integer');
    $this->assertCount(1, $integerFields['test_entity_type']);
    $this->assertArrayNotHasKey('non_fieldable', $integerFields);
    $this->assertArrayHasKey('id', $integerFields['test_entity_type']);
    $this->assertArrayNotHasKey('by_bundle', $integerFields['test_entity_type']);

    $stringFields = $this->entityFieldManager->getFieldMapByFieldType('string');
    $this->assertCount(1, $stringFields['test_entity_type']);
    $this->assertArrayNotHasKey('non_fieldable', $stringFields);
    $this->assertArrayHasKey('by_bundle', $stringFields['test_entity_type']);
    $this->assertArrayNotHasKey('id', $stringFields['test_entity_type']);
  }

}
protected function renderLink($data, ResultRow $values) {
    if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
      $node_type = $this->getValue($values, 'type');
      $node = Node::create([
        'nid' => $this->getValue($values, 'nid'),
        'type' => $node_type,
      ]);
      // Because there is no support for selecting a specific comment field to       // reference, we arbitrarily use the first such field name we find.       // @todo Provide a means for selecting the comment field.       // https://www.drupal.org/node/2594201       $field_map = $this->entityFieldManager->getFieldMapByFieldType('comment');
      $comment_field_name = 'comment';
      foreach ($field_map['node'] as $field_name => $field_data) {
        foreach ($field_data['bundles'] as $bundle_name) {
          if ($node_type == $bundle_name) {
            $comment_field_name = $field_name;
            break 2;
          }
        }
      }
      $page_number = $this->entityTypeManager->getStorage('comment')
        ->getNewCommentPageNumber($this->getValue($values, 'comment_count')$this->getValue($values)$node$comment_field_name);
      
$base_plugin_id,
      $container->get('entity_field.manager'),
      $container->get('entity_type.manager')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Get all entity reference fields.     $field_map = $this->entityFieldManager->getFieldMapByFieldType('entity_reference');

    foreach ($field_map as $entity_type => $fields) {
      foreach ($fields as $field_name => $field) {
        foreach ($field['bundles'] as $bundle) {
          $field_definitions = $this->entityFieldManager->getFieldDefinitions($entity_type$bundle);
          $target_type = $field_definitions[$field_name]->getSetting('target_type');

          // If the field's target type is not supported, skip it.           if (!array_key_exists($target_type$base_plugin_definition['target_types'])) {
            continue;
          }

          


  /** * {@inheritdoc} */
  public function getFields($entity_type_id) {
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      return [];
    }

    $map = $this->entityFieldManager->getFieldMapByFieldType('comment');
    return $map[$entity_type_id] ?? [];
  }

  /** * {@inheritdoc} */
  public function addBodyField($comment_type_id) {
    if (!FieldConfig::loadByName('comment', $comment_type_id, 'comment_body')) {
      // Attaches the body field by default.       $field = $this->entityTypeManager->getStorage('field_config')->create([
        'label' => 'Comment',
        

  protected static function getCommentAccessCondition(EntityTypeInterface $comment_entity_type, AccountInterface $current_user, CacheableMetadata $cacheability$depth = 1) {
    // If a comment is assigned to another entity or author the cache needs to     // be invalidated.     $cacheability->addCacheTags($comment_entity_type->getListCacheTags());
    // Constructs a big EntityConditionGroup which will filter comments based on     // the current user's access to the entities on which each comment lives.     // This is especially complex because comments of different bundles can     // live on entities of different entity types.     $comment_entity_type_id = $comment_entity_type->id();
    $field_map = static::$fieldManager->getFieldMapByFieldType('entity_reference');
    assert(isset($field_map[$comment_entity_type_id]['entity_id']['bundles']), 'Every comment has an `entity_id` field.');
    $bundle_ids_by_target_entity_type_id = [];
    foreach ($field_map[$comment_entity_type_id]['entity_id']['bundles'] as $bundle_id) {
      $field_definitions = static::$fieldManager->getFieldDefinitions($comment_entity_type_id$bundle_id);
      $commented_entity_field_definition = $field_definitions['entity_id'];
      // Each commented entity field definition has a setting which indicates       // the entity type of the commented entity reference field. This differs       // per bundle.       $target_entity_type_id = $commented_entity_field_definition->getSetting('target_type');
      $bundle_ids_by_target_entity_type_id[$target_entity_type_id][] = $bundle_id;
    }
    
Home | Imprint | This part of the site doesn't use cookies.