You are here

public function DiffBuilderManager::showDiff in Diff 8

Define whether a field should be displayed or not as a diff change.

To define if a field should be displayed in the diff comparison, check if it is revisionable and is not the bundle or revision field of the entity.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition: The field storage definition.

Return value

bool TRUE if the field will be displayed.

File

src/DiffBuilderManager.php, line 94

Class

DiffBuilderManager
Plugin type manager for field diff builders.

Namespace

Drupal\diff

Code

public function showDiff(FieldStorageDefinitionInterface $field_storage_definition) {
  $show_diff = FALSE;

  // Check if the field is revisionable.
  if ($field_storage_definition
    ->isRevisionable()) {
    $show_diff = TRUE;

    // Do not display the field, if it is the bundle or revision field of the
    // entity.
    $entity_type = $this->entityTypeManager
      ->getDefinition($field_storage_definition
      ->getTargetEntityTypeId());

    // @todo Don't hard code fields after: https://www.drupal.org/node/2248983
    if (in_array($field_storage_definition
      ->getName(), [
      'revision_log',
      'revision_uid',
      $entity_type
        ->getKey('bundle'),
      $entity_type
        ->getKey('revision'),
    ])) {
      $show_diff = FALSE;
    }
  }
  return $show_diff;
}