You are here

class FieldComparatorDefault in Conflict 8.2

Default field comparator plugin implementation covering all fields.

Plugin annotation


@FieldComparator(
  id = "conflict_field_comparator_default",
  entity_type_id = "*",
  bundle = "*",
  field_type = "*",
  field_name = "*",
)

Hierarchy

Expanded class hierarchy of FieldComparatorDefault

1 file declares its use of FieldComparatorDefault
FieldComparatorParagraphReference.php in modules/conflict_paragraphs/src/Plugin/Conflict/FieldComparator/FieldComparatorParagraphReference.php

File

src/Plugin/Conflict/FieldComparator/FieldComparatorDefault.php, line 22

Namespace

Drupal\conflict\Plugin\Conflict\FieldComparator
View source
class FieldComparatorDefault extends PluginBase implements FieldComparatorInterface {

  /**
   * {@inheritdoc}
   */
  public function hasChanged(FieldItemListInterface $field_item_list_a, FieldItemListInterface $field_item_list_b, $langcode = NULL, $entity_type_id = NULL, $bundle = NULL, $field_type = NULL, $field_name = NULL) {
    $equals = $field_item_list_a
      ->equals($field_item_list_b);
    return !$equals;
  }

  /**
   * {@inheritdoc}
   */
  public function getConflictType(FieldItemListInterface $local, FieldItemListInterface $server, FieldItemListInterface $original, $langcode, $entity_type_id, $bundle, $field_type, $field_name) {

    // Check for changes between the server and the locally edited version.
    if ($this
      ->hasChanged($server, $local, $langcode, $entity_type_id, $bundle, $field_type, $field_name)) {

      // Check for changes between the server and the locally used original
      // version.
      if ($this
        ->hasChanged($server, $original, $langcode, $entity_type_id, $bundle, $field_type, $field_name)) {

        // Check for changes between the locally edited and locally used
        // original version.
        $conflict_type = $this
          ->hasChanged($local, $original, $langcode, $entity_type_id, $bundle, $field_type, $field_name) ? ConflictTypes::CONFLICT_TYPE_LOCAL_REMOTE : ConflictTypes::CONFLICT_TYPE_REMOTE;
        return $conflict_type;
      }
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {

    // By default, field comparators are available for all fields.
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FieldComparatorDefault::getConflictType public function Returns the conflict type for a field. Overrides FieldComparatorInterface::getConflictType 1
FieldComparatorDefault::hasChanged public function Checks whether the field items have changed. Overrides FieldComparatorInterface::hasChanged
FieldComparatorDefault::isApplicable public static function Returns if the field comparator can be used for the provided field. Overrides FieldComparatorInterface::isApplicable 1
FieldComparatorInterface::APPLIES_TO_ALL constant The identifier to be used by the plugin annotation and hasChanged().
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.