public function DraggableViewsSyncExtend::extendPull in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x modules/cms_content_sync_draggableviews/src/EventSubscriber/DraggableViewsSyncExtend.php \Drupal\cms_content_sync_draggableviews\EventSubscriber\DraggableViewsSyncExtend::extendPull()
- 2.0.x modules/cms_content_sync_draggableviews/src/EventSubscriber/DraggableViewsSyncExtend.php \Drupal\cms_content_sync_draggableviews\EventSubscriber\DraggableViewsSyncExtend::extendPull()
@internal param $entity @internal param $intent
Parameters
\Drupal\cms_content_sync\Event\BeforeEntityPull $event:
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- modules/
cms_content_sync_draggableviews/ src/ EventSubscriber/ DraggableViewsSyncExtend.php, line 128
Class
- DraggableViewsSyncExtend
- Event subscriptions for events dispatched by Content Sync.
Namespace
Drupal\cms_content_sync_draggableviews\EventSubscriberCode
public function extendPull(AfterEntityPull $event) {
$intent = $event
->getIntent();
$entity = $event
->getEntity();
if (!$this
->supportsEntityType($entity
->getEntityTypeId())) {
return;
}
// Field Collection entities are causing an exception when used
// with draggable views.
if ($entity instanceof FieldCollectionItem) {
return;
}
$values = $intent
->getProperty(self::PROPERTY_NAME);
if (empty($values)) {
return;
}
$connection = Database::getConnection();
foreach ($values as $view_name => $view_values) {
foreach ($view_values as $view_display => $display_values) {
// Remove old data.
$connection
->delete('draggableviews_structure')
->condition('view_name', $view_name)
->condition('view_display', $view_display)
->condition('entity_id', $entity
->id())
->execute();
// Add new data.
$record = [
'view_name' => $view_name,
'view_display' => $view_display,
'args' => $display_values['args'],
'entity_id' => $entity
->id(),
'weight' => $display_values['weight'],
'parent' => $display_values['parent'],
];
$connection
->insert('draggableviews_structure')
->fields($record)
->execute();
}
}
}