class DefaultNodeHandler in CMS Content Sync 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/cms_content_sync/entity_handler/DefaultNodeHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultNodeHandler
- 2.1.x src/Plugin/cms_content_sync/entity_handler/DefaultNodeHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultNodeHandler
Class DefaultNodeHandler, providing proper handling for published/unpublished content.
Plugin annotation
@EntityHandler(
id = "cms_content_sync_default_node_handler",
label = @Translation("Default Node"),
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\EntityHandlerBase implements EntityHandlerInterface, ContainerFactoryPluginInterface
- class \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultNodeHandler
- class \Drupal\cms_content_sync\Plugin\EntityHandlerBase implements EntityHandlerInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DefaultNodeHandler
File
- src/
Plugin/ cms_content_sync/ entity_handler/ DefaultNodeHandler.php, line 22
Namespace
Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handlerView source
class DefaultNodeHandler extends EntityHandlerBase {
public const USER_PROPERTY = 'uid';
public const USER_REVISION_PROPERTY = 'revision_uid';
public const REVISION_TRANSLATION_AFFECTED_PROPERTY = 'revision_translation_affected';
/**
* {@inheritdoc}
*/
public static function supports($entity_type, $bundle) {
return 'node' == $entity_type;
}
/**
* {@inheritdoc}
*/
public function getAllowedPushOptions() {
return [
PushIntent::PUSH_DISABLED,
PushIntent::PUSH_AUTOMATICALLY,
PushIntent::PUSH_AS_DEPENDENCY,
PushIntent::PUSH_MANUALLY,
];
}
/**
* {@inheritdoc}
*/
public function push(PushIntent $intent, EntityInterface $entity = null) {
if (!parent::push($intent, $entity)) {
return false;
}
if (!$entity) {
$entity = $intent
->getEntity();
}
/**
* @var \Drupal\node\NodeInterface $entity
*/
$this
->setDateProperty($intent, 'created', intval($entity
->getCreatedTime()));
return true;
}
/**
* {@inheritdoc}
*/
public function setEntityValues(PullIntent $intent, FieldableEntityInterface $entity = null) {
if (!$entity) {
$entity = $intent
->getEntity();
}
$entity
->setRevisionCreationTime(time());
if ($intent
->getProperty('revision_log')) {
$entity
->setRevisionLogMessage(reset($intent
->getProperty('revision_log')[0]));
}
return parent::setEntityValues($intent, $entity);
}
/**
* {@inheritdoc}
*/
public function getAllowedPreviewOptions() {
return [
'table' => 'Table',
'preview_mode' => 'Preview mode',
];
}
/**
* {@inheritdoc}
*/
public function getHandlerSettings($current_values, $type = 'both') {
$options = parent::getHandlerSettings($current_values, $type);
// @todo Move to default handler for all entities that can be published.
$options['ignore_unpublished'] = [
'#type' => 'checkbox',
'#title' => 'Ignore unpublished content',
'#default_value' => isset($current_values['ignore_unpublished']) && 0 === $current_values['ignore_unpublished'] ? 0 : 1,
];
$options['allow_explicit_unpublishing'] = [
'#type' => 'checkbox',
'#title' => 'Allow explicit unpublishing',
'#default_value' => isset($current_values['allow_explicit_unpublishing']) && 0 === $current_values['allow_explicit_unpublishing'] ? 0 : 1,
];
return $options;
}
/**
* {@inheritdoc}
*/
public function ignorePull(PullIntent $intent) {
// Not published? Ignore this revision then.
if (empty($intent
->getProperty('status')[0]['value']) && $this->settings['handler_settings']['ignore_unpublished']) {
if (!$this->settings['handler_settings']['allow_explicit_unpublishing'] || SyncIntent::ACTION_CREATE === $intent
->getAction()) {
// Unless it's a delete, then it won't have a status and is independent
// of published state, so we don't ignore the pull.
if (SyncIntent::ACTION_DELETE != $intent
->getAction()) {
return true;
}
}
}
return parent::ignorePull($intent);
}
/**
* {@inheritdoc}
*/
public function ignorePush(PushIntent $intent) {
/**
* @var \Drupal\node\NodeInterface $entity
*/
$entity = $intent
->getEntity();
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$node = $node_storage
->load($entity
->id());
if (!$entity
->isPublished() && $this->settings['handler_settings']['ignore_unpublished']) {
if (!$this->settings['handler_settings']['allow_explicit_unpublishing'] || $node
->isPublished() || $entity
->getRevisionId() == $node
->getRevisionId() && !$intent
->getEntityStatus()
->getLastPush()) {
return true;
}
}
return parent::ignorePush($intent);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultNodeHandler:: |
public | function |
Overrides EntityHandlerInterface:: |
|
DefaultNodeHandler:: |
public | function |
Get the allowed push options. Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | function |
Get the handler settings. Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | function |
Check if the pull should be ignored. Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | function |
Check if the entity should not be ignored from the push. Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | function |
Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | constant |
Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | function |
Set the values for the pulled entity. Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public static | function |
Check if this handler supports the given entity type. Overrides EntityHandlerInterface:: |
|
DefaultNodeHandler:: |
public | constant |
Overrides EntityHandlerBase:: |
|
DefaultNodeHandler:: |
public | constant |
Overrides EntityHandlerBase:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityHandlerBase:: |
protected | property | ||
EntityHandlerBase:: |
protected | property | ||
EntityHandlerBase:: |
protected | property | A sync instance. | |
EntityHandlerBase:: |
protected | property | A logger instance. | |
EntityHandlerBase:: |
protected | property | ||
EntityHandlerBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
EntityHandlerBase:: |
protected | function | 1 | |
EntityHandlerBase:: |
protected | function | Delete a entity. | |
EntityHandlerBase:: |
public | function |
Get the allowed pull options. Overrides EntityHandlerInterface:: |
2 |
EntityHandlerBase:: |
protected | function | ||
EntityHandlerBase:: |
protected | function | ||
EntityHandlerBase:: |
public | function |
Provide a list of fields that are not allowed to be pushed or pulled.
These fields typically contain all label fields that are pushed
separately anyway (we don't want to set IDs and revision IDs of entities
for example, but only use the UUID for… Overrides EntityHandlerInterface:: |
4 |
EntityHandlerBase:: |
protected | function | Get a list of fields that can't be updated. | |
EntityHandlerBase:: |
public | function |
Overrides EntityHandlerInterface:: |
2 |
EntityHandlerBase:: |
protected | function | Check whether the entity type supports having a label. | 2 |
EntityHandlerBase:: |
protected | function | ||
EntityHandlerBase:: |
public | function |
Pull the remote entity. Overrides EntityHandlerInterface:: |
4 |
EntityHandlerBase:: |
protected | function | Whether or not menu item references should be pushed. | |
EntityHandlerBase:: |
protected | function | 1 | |
EntityHandlerBase:: |
protected | function | ||
EntityHandlerBase:: |
protected | function | ||
EntityHandlerBase:: |
public | function |
Update the entity type definition. Overrides EntityHandlerInterface:: |
3 |
EntityHandlerBase:: |
public | function |
Validate the settings defined above. $form and $form_state are the same as
in the Form API. $settings_key is the index at $form['sync_entities'] for
this handler instance. Overrides EntityHandlerInterface:: |
|
EntityHandlerBase:: |
public | function |
Constructs a Drupal\rest\Plugin\ResourceBase object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |