You are here

protected function EntitySharePathautoEnhancer::doUndoTransform in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/jsonapi/FieldEnhancer/EntitySharePathautoEnhancer.php \Drupal\entity_share\Plugin\jsonapi\FieldEnhancer\EntitySharePathautoEnhancer::doUndoTransform()

File

src/Plugin/jsonapi/FieldEnhancer/EntitySharePathautoEnhancer.php, line 76

Class

EntitySharePathautoEnhancer
Prepare path value to be able to handle pathauto metadata.

Namespace

Drupal\entity_share\Plugin\jsonapi\FieldEnhancer

Code

protected function doUndoTransform($data, Context $context) {
  $configuration = $this
    ->getConfiguration();
  switch ($configuration['behavior']) {
    case self::EXPOSE_CURRENT_PATHAUTO:

      /** @var \Drupal\Core\Field\FieldItemInterface $field_item */
      $field_item = $context['field_item_object'];
      $entity = $field_item
        ->getEntity();
      $entity_type_id = $entity
        ->getEntityTypeId();
      $key = PathautoState::getPathautoStateKey($entity
        ->id());
      $state = $this->keyValue
        ->get("pathauto_state.{$entity_type_id}")
        ->get($key);
      if (!is_null($state)) {
        $data['pathauto'] = $state;
      }
      else {
        $data['pathauto'] = 0;
      }
      break;
    case self::FORCE_ENABLE_PATHAUTO:
      $data['pathauto'] = 1;
      break;
    case self::FORCE_DISABLE_PATHAUTO:
      $data['pathauto'] = 0;
      break;
  }
  return $data;
}