You are here

public function DiffBuilderManager::isFieldStorageDefinitionDisplayed in Diff 8

Determines if the field is displayed.

Determines if a field should be displayed when comparing revisions based on the entity view display if there is no plugin selected for the field.

Parameters

FieldStorageDefinitionInterface $field_storage_definition: The field name.

Return value

bool Whether the field is displayed.

1 call to DiffBuilderManager::isFieldStorageDefinitionDisplayed()
DiffBuilderManager::getSelectedPluginForFieldStorageDefinition in src/DiffBuilderManager.php
Selects a default plugin for a field storage definition.

File

src/DiffBuilderManager.php, line 179

Class

DiffBuilderManager
Plugin type manager for field diff builders.

Namespace

Drupal\diff

Code

public function isFieldStorageDefinitionDisplayed(FieldStorageDefinitionInterface $field_storage_definition) {
  if ($field_storage_definition instanceof BaseFieldDefinition && $field_storage_definition
    ->isDisplayConfigurable('view') || $field_storage_definition instanceof FieldStorageConfig) {
    $field_key = 'content.' . $field_storage_definition
      ->getName() . '.type';
    $storage = $this->entityTypeManager
      ->getStorage('entity_view_display');
    $query = $storage
      ->getQuery()
      ->condition('targetEntityType', $field_storage_definition
      ->getTargetEntityTypeId());
    if ($field_storage_definition instanceof FieldStorageConfig) {
      $bundles = $field_storage_definition
        ->getBundles();
      $query
        ->condition('bundle', (array) $bundles, 'IN');
    }
    $result = $query
      ->exists($field_key)
      ->range(0, 1)
      ->execute();
    return !empty($result) ? TRUE : FALSE;
  }
  else {
    $view_options = (bool) $field_storage_definition
      ->getDisplayOptions('view');
    return $view_options;
  }
}