예제 #1
0
 /**
  * Validates request attributes.
  */
 protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode)
 {
     // Validate the field name and language.
     if (!$field_name || !$entity->hasField($field_name)) {
         return FALSE;
     }
     if (!$langcode || !$entity->hasTranslation($langcode)) {
         return FALSE;
     }
     return TRUE;
 }
 /**
  * Returns the name of the field that implements the changed timestamp.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity being tested.
  *
  * @return string
  *   The the field name.
  */
 protected function getChangedFieldName($entity)
 {
     return $entity->hasField('content_translation_changed') ? 'content_translation_changed' : 'changed';
 }
 /**
  * {@inheritdoc}
  */
 public function setChangedTime($timestamp)
 {
     $field_name = $this->translation->hasField('content_translation_changed') ? 'content_translation_changed' : 'changed';
     $this->translation->set($field_name, $timestamp);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function updateAlias(EntityInterface $entity, $op, array $options = array())
 {
     // Skip if the entity does not have the path field.
     if (!$entity instanceof ContentEntityInterface || !$entity->hasField('path')) {
         return NULL;
     }
     // Skip if pathauto processing is disabled.
     if (isset($entity->path->pathauto) && empty($entity->path->pathauto) && empty($options['force'])) {
         return NULL;
     }
     $options += array('language' => $entity->language()->getId());
     $type = $entity->getEntityTypeId();
     $bundle = $entity->bundle();
     // Skip processing if the entity has no pattern.
     if (!$this->getPatternByEntity($type, $bundle, $options['language'])) {
         return NULL;
     }
     // Deal with taxonomy specific logic.
     if ($type == 'taxonomy_term') {
         $config_forum = $this->configFactory->get('forum.settings');
         if ($entity->getVocabularyId() == $config_forum->get('vocabulary')) {
             $type = 'forum';
         }
     }
     $result = $this->createAlias($type, $op, '/' . $entity->urlInfo()->getInternalPath(), array($type => $entity), $bundle, $options['language']);
     if ($type == 'taxonomy_term' && empty($options['is_child'])) {
         // For all children generate new aliases.
         $options['is_child'] = TRUE;
         unset($options['language']);
         foreach ($this->getTermTree($entity->getVocabularyId(), $entity->id(), NULL, TRUE) as $subterm) {
             $this->updateAlias($subterm, $op, $options);
         }
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function updateEntityAlias(EntityInterface $entity, $op, array $options = array())
 {
     // Skip if the entity does not have the path field.
     if (!$entity instanceof ContentEntityInterface || !$entity->hasField('path')) {
         return NULL;
     }
     // Skip if pathauto processing is disabled.
     if ($entity->path->pathauto != PathautoState::CREATE && empty($options['force'])) {
         return NULL;
     }
     $options += array('language' => $entity->language()->getId());
     $type = $entity->getEntityTypeId();
     // Skip processing if the entity has no pattern.
     if (!$this->getPatternByEntity($entity)) {
         return NULL;
     }
     // Deal with taxonomy specific logic.
     // @todo Update and test forum related code.
     if ($type == 'taxonomy_term') {
         $config_forum = $this->configFactory->get('forum.settings');
         if ($entity->getVocabularyId() == $config_forum->get('vocabulary')) {
             $type = 'forum';
         }
     }
     try {
         $result = $this->createEntityAlias($entity, $op);
     } catch (\InvalidArgumentException $e) {
         drupal_set_message($e->getMessage(), 'error');
         return NULL;
     }
     // @todo Move this to a method on the pattern plugin.
     if ($type == 'taxonomy_term') {
         foreach ($this->loadTermChildren($entity->id()) as $subterm) {
             $this->updateEntityAlias($subterm, $op, $options);
         }
     }
     return $result;
 }
 /**
  * Initializes the translation form state.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  * @param \Drupal\Core\Entity\EntityInterface $host
  */
 protected function initIsTranslating(FormStateInterface $form_state, EntityInterface $host)
 {
     if ($this->isTranslating != NULL) {
         return;
     }
     $this->isTranslating = FALSE;
     if (!$host->isTranslatable()) {
         return;
     }
     if (!$host->getEntityType()->hasKey('default_langcode')) {
         return;
     }
     $default_langcode_key = $host->getEntityType()->getKey('default_langcode');
     if (!$host->hasField($default_langcode_key)) {
         return;
     }
     if (!empty($form_state->get('content_translation'))) {
         // Adding a language through the ContentTranslationController.
         $this->isTranslating = TRUE;
     }
     if ($host->hasTranslation($form_state->get('langcode')) && $host->getTranslation($form_state->get('langcode'))->get($default_langcode_key)->value == 0) {
         // Editing a translation.
         $this->isTranslating = TRUE;
     }
 }