public function DefaultTaxonomyHandler::push in CMS Content Sync 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/cms_content_sync/entity_handler/DefaultTaxonomyHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultTaxonomyHandler::push()
- 2.1.x src/Plugin/cms_content_sync/entity_handler/DefaultTaxonomyHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultTaxonomyHandler::push()
Parameters
\Drupal\cms_content_sync\PushIntent $intent: The request to store all relevant info at
Return value
bool Whether or not the content has been pushed. FALSE is a desired state, meaning nothing should be pushed according to config.
Throws
\Drupal\cms_content_sync\Exception\SyncException
Overrides EntityHandlerBase::push
File
- src/
Plugin/ cms_content_sync/ entity_handler/ DefaultTaxonomyHandler.php, line 176
Class
- DefaultTaxonomyHandler
- Class DefaultTaxonomyHandler.
Namespace
Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handlerCode
public function push(PushIntent $intent, EntityInterface $entity = null) {
/**
* @var \Drupal\file\FileInterface $entity
*/
if (!$entity) {
$entity = $intent
->getEntity();
}
if (!parent::push($intent)) {
return false;
}
$term_storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$parents = $term_storage
->loadParents($entity
->id());
if (count($parents)) {
$parent_term = reset($parents);
$parent = $intent
->addDependency($parent_term);
$intent
->setProperty('parent', $parent);
}
// Since taxonomy terms ain't got a created date, we set the changed
// date instead during the first push.
$status_entity = $intent
->getEntityStatus();
if (is_null($status_entity
->getLastPush())) {
$this
->setDateProperty($intent, 'created', (int) $entity
->getChangedTime());
}
return true;
}