public function DefaultTaxonomyHandler::push in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Plugin/cms_content_sync/entity_handler/DefaultTaxonomyHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultTaxonomyHandler::push()
- 2.0.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())) {
$intent
->setProperty('created', (int) $entity
->getChangedTime());
}
return true;
}