class DefaultFieldCollectionHandler in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Plugin/cms_content_sync/field_handler/DefaultFieldCollectionHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultFieldCollectionHandler
- 2.0.x src/Plugin/cms_content_sync/field_handler/DefaultFieldCollectionHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultFieldCollectionHandler
Providing a minimalistic implementation for any field type.
Plugin annotation
@FieldHandler(
id = "cms_content_sync_default_field_collection_handler",
label = @Translation("Default Field Collection"),
weight = 90
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\cms_content_sync\Plugin\FieldHandlerBase implements FieldHandlerInterface, ContainerFactoryPluginInterface
- class \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase
- class \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultEntityReferenceHandler
- class \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultFieldCollectionHandler
- class \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultEntityReferenceHandler
- class \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase
- class \Drupal\cms_content_sync\Plugin\FieldHandlerBase implements FieldHandlerInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DefaultFieldCollectionHandler
1 file declares its use of DefaultFieldCollectionHandler
- DefaultFieldCollectionItemHandler.php in src/
Plugin/ cms_content_sync/ entity_handler/ DefaultFieldCollectionItemHandler.php
File
- src/
Plugin/ cms_content_sync/ field_handler/ DefaultFieldCollectionHandler.php, line 17
Namespace
Drupal\cms_content_sync\Plugin\cms_content_sync\field_handlerView source
class DefaultFieldCollectionHandler extends DefaultEntityReferenceHandler {
/**
* @var \Drupal\cms_content_sync\Plugin\FieldHandlerInterface
*/
public static $currentFieldHandler;
/**
* @var \Drupal\cms_content_sync\PullIntent
*/
public static $currentPullIntent;
/**
* {@inheritdoc}
*/
public static function supports($entity_type, $bundle, $field_name, FieldDefinitionInterface $field) {
if (!in_array($field
->getType(), [
'field_collection',
])) {
return false;
}
return true;
}
/**
* {@inheritdoc}
*/
protected function forceEmbeddingReferencedEntities() {
return true;
}
/**
* {@inheritdoc}
*/
protected function getReferencedEntityTypes() {
return [
'field_collection_item',
];
}
/**
* {@inheritdoc}
*/
protected function loadReferencedEntity(PullIntent $intent, $definition) {
$previousFieldHandler = self::$currentFieldHandler;
$previousPullIntent = self::$currentPullIntent;
// Expose current field and intent (to reference host entity)
// As field collections require this when being created.
self::$currentFieldHandler = $this;
self::$currentPullIntent = $intent;
$entity = parent::loadReferencedEntity($intent, $definition);
self::$currentFieldHandler = $previousFieldHandler;
self::$currentPullIntent = $previousPullIntent;
return $entity;
}
/**
* {@inheritdoc}
*/
protected function loadReferencedEntityFromFieldValue($value) {
if (empty($value['revision_id'])) {
return null;
}
return \Drupal::entityTypeManager()
->getStorage('field_collection_item')
->loadRevision($value['revision_id']);
}
protected function getInvalidSubfields() {
return [
'_accessCacheability',
'_attributes',
'_loaded',
'top',
'target_revision_id',
'subform',
'value',
'revision_id',
];
}
/**
* @param $reference
* @param \Drupal\cms_content_sync\PullIntent $intent
*
* @return array
*/
protected function getFieldValuesForReference($reference, $intent) {
$entity = $intent
->getEntity();
$reference->host_type = $entity
->getEntityTypeId();
$reference->host_id = $entity
->id();
$reference->host_entity = $entity;
$reference->field_name = $this->fieldName;
$reference
->save(true);
return [
'value' => $reference
->id(),
'revision_id' => $reference
->getRevisionId(),
];
}
}