You are here

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

Same name and namespace in other branches
  1. 8 src/Plugin/cms_content_sync/field_handler/DefaultVideoHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultVideoHandler::push()
  2. 2.1.x src/Plugin/cms_content_sync/field_handler/DefaultVideoHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultVideoHandler::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/DefaultVideoHandler.php, line 98

Class

DefaultVideoHandler
Providing a minimalistic implementation for any field type.

Namespace

Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler

Code

public function push(PushIntent $intent) {
  $action = $intent
    ->getAction();

  /**
   * @var \Drupal\Core\Entity\FieldableEntityInterface $entity
   */
  $entity = $intent
    ->getEntity();

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

    /**
     * @var \Drupal\file\Entity\FileInterface $file
     */
    $file = File::load($value['target_id']);
    if ($file) {
      unset($value['target_id']);
      $uri = $file
        ->getFileUri();
      if ('public://' == substr($uri, 0, 9) || 'private://' == substr($uri, 0, 10)) {
        $result[] = $intent
          ->addDependency($file, $value);
      }
      else {
        $value['uri'] = $uri;
        $value['uuid'] = $file
          ->uuid();
        $value['mimetype'] = $file
          ->getMimeType();
        $result[] = $value;
      }
    }
  }
  $intent
    ->setProperty($this->fieldName, $result);
  return true;
}