You are here

public function DefaultPathHandler::push in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/cms_content_sync/field_handler/DefaultPathHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultPathHandler::push()
  2. 2.1.x src/Plugin/cms_content_sync/field_handler/DefaultPathHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultPathHandler::push()

Parameters

\Drupal\cms_content_sync\SyncIntent $intent:

Return value

bool Whether or not the content has been pushed. FALSE is a desired state, meaning the entity should not be pushed according to config.

Throws

\Drupal\cms_content_sync\Exception\SyncException

Overrides FieldHandlerBase::push

File

src/Plugin/cms_content_sync/field_handler/DefaultPathHandler.php, line 33

Class

DefaultPathHandler
Providing an implementation for the "path" field type of content entities.

Namespace

Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler

Code

public function push(PushIntent $intent) {
  $action = $intent
    ->getAction();
  $entity = $intent
    ->getEntity();
  if (PushIntent::PUSH_AUTOMATICALLY != $this->settings['export']) {
    return false;
  }

  // Deletion doesn't require any action on field basis for static data.
  if (SyncIntent::ACTION_DELETE == $action) {
    return false;
  }
  $value = $entity
    ->get($this->fieldName)
    ->getValue();

  // Support the pathauto module.
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('pathauto')) {
    $value[0]['pathauto'] = $entity->path->pathauto;
  }
  if (!empty($value)) {
    unset($value[0]['pid'], $value[0]['source']);
    $intent
      ->setProperty($this->fieldName, $value);
  }
  return true;
}