/**
   * Build all necessary things for child form (form state, etc.).
   *
   * @param \Drupal\Core\Entity\EntityFormInterface $controller
   *   Entity form controller for child form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   Parent form state object.
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   Entity object.
   * @param string $operation
   *   Operation that is to be performed in inline form.
   * @param array $parents
   *   Entity form #parents.
   *
   * @return \Drupal\Core\Form\FormStateInterface
   *   Child form state object.
   */
  public static function buildChildFormState(EntityFormInterface $controller, FormStateInterface $form_state, EntityInterface $entity, $operation, $parents) {
    $child_form_state = new FormState();

    $child_form_state->addBuildInfo('callback_object', $controller);
    $child_form_state->addBuildInfo('base_form_id', $controller->getBaseFormID());
    $child_form_state->addBuildInfo('form_id', $controller->getFormID());
    $child_form_state->addBuildInfo('args', array());

    // Copy values to child form.
    $child_form_state->setCompleteForm($form_state->getCompleteForm());
    $child_form_state->setUserInput($form_state->getUserInput());

    // Filter out all submitted values that are not directly relevant for this
    // IEF. Otherwise they might mess things up.
    $form_state_values = $form_state->getValues();
    $form_state_values = static::extractArraySequence($form_state_values, $parents);

    $child_form_state->setValues($form_state_values);
    $child_form_state->setStorage($form_state->getStorage());
    $value = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.' . $operation);
    $child_form_state->set('form_display', $value);

    // Since some of the submit handlers are run, redirects need to be disabled.
    $child_form_state->disableRedirect();

    // When a form is rebuilt after Ajax processing, its #build_id and #action
    // should not change.
    // @see drupal_rebuild_form()
    $rebuild_info = $child_form_state->getRebuildInfo();
    $rebuild_info['copy']['#build_id'] = TRUE;
    $rebuild_info['copy']['#action'] = TRUE;
    $child_form_state->setRebuildInfo($rebuild_info);

    $child_form_state->set('inline_entity_form', $form_state->get('inline_entity_form'));
    $child_form_state->set('langcode', $entity->language()->getId());

    $child_form_state->set('field', $form_state->get('field'));
    $child_form_state->setTriggeringElement($form_state->getTriggeringElement());
    $child_form_state->setSubmitHandlers($form_state->getSubmitHandlers());

    return $child_form_state;
  }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array())
 {
     $translation = $entity;
     if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) {
         if (empty($langcode)) {
             $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
             $entity->addCacheContexts(['languages:' . LanguageInterface::TYPE_CONTENT]);
         }
         // Retrieve language fallback candidates to perform the entity language
         // negotiation, unless the current translation is already the desired one.
         if ($entity->language()->getId() != $langcode) {
             $context['data'] = $entity;
             $context += array('operation' => 'entity_view', 'langcode' => $langcode);
             $candidates = $this->languageManager->getFallbackCandidates($context);
             // Ensure the default language has the proper language code.
             $default_language = $entity->getUntranslated()->language();
             $candidates[$default_language->getId()] = LanguageInterface::LANGCODE_DEFAULT;
             // Return the most fitting entity translation.
             foreach ($candidates as $candidate) {
                 if ($entity->hasTranslation($candidate)) {
                     $translation = $entity->getTranslation($candidate);
                     break;
                 }
             }
         }
     }
     return $translation;
 }
 /**
  * {@inheritdoc}
  */
 public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE)
 {
     $account = $this->prepareUser($account);
     $langcode = $entity->language()->getId();
     if (($return = $this->getCache($entity->uuid(), $operation, $langcode, $account)) !== NULL) {
         // Cache hit, no work necessary.
         return $return_as_object ? $return : $return->isAllowed();
     }
     // Invoke hook_entity_access() and hook_ENTITY_TYPE_access(). Hook results
     // take precedence over overridden implementations of
     // EntityAccessControlHandler::checkAccess(). Entities that have checks that
     // need to be done before the hook is invoked should do so by overriding
     // this method.
     // We grant access to the entity if both of these conditions are met:
     // - No modules say to deny access.
     // - At least one module says to grant access.
     $access = array_merge($this->moduleHandler()->invokeAll('entity_access', [$entity, $operation, $account]), $this->moduleHandler()->invokeAll($entity->getEntityTypeId() . '_access', [$entity, $operation, $account]));
     $return = $this->processAccessHookResults($access);
     // Also execute the default access check except when the access result is
     // already forbidden, as in that case, it can not be anything else.
     if (!$return->isForbidden()) {
         $return = $return->orIf($this->checkAccess($entity, $operation, $account));
     }
     $result = $this->setCache($return, $entity->uuid(), $operation, $langcode, $account);
     return $return_as_object ? $result : $result->isAllowed();
 }
 /**
  * {@inheritdoc}
  */
 public function retranslate(EntityInterface $entity, $langcode = NULL)
 {
     $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->id;
     $translations = $entity->getTranslationLanguages();
     foreach ($translations as $langcode => $language) {
         $entity->translation[$langcode]['outdated'] = $langcode != $updated_langcode;
     }
 }
 public function assertNoEntityAlias(EntityInterface $entity, $langcode = NULL)
 {
     // By default, use the entity language.
     if (!$langcode) {
         $langcode = $entity->language()->getId();
     }
     $this->assertEntityAlias($entity, '/' . $entity->urlInfo()->getInternalPath(), $langcode);
 }
 /**
  * Creates entity path alias.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity that should get an alias.
  * @param string $alias
  *   The alias to be created.
  */
 protected function doExecute(EntityInterface $entity, $alias)
 {
     // We need to save the entity before we can get its internal path.
     if ($entity->isNew()) {
         $entity->save();
     }
     $path = $entity->urlInfo()->getInternalPath();
     $langcode = $entity->language()->getId();
     $this->aliasStorage->save($path, $alias, $langcode);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['name']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#url' => $uri);
     $row['scales']['data'] = array('#type' => 'markup', '#markup' => implode(', ', $entity->getScales()));
     return $row + parent::buildRow($entity);
 }
Exemple #8
0
 /**
  * @inheritDoc
  */
 public function buildRow(EntityInterface $entity)
 {
     $langcode = $entity->language()->getId();
     $uri = $entity->urlInfo();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['fullname']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#url' => $uri);
     $row['shortname']['data'] = array('#markup' => $entity->get('shortname')->value);
     $row['category']['data'] = array('#markup' => $entity->getCategoryInstance() ? $entity->getCategoryInstance()->get('name')->value : '');
     $row['timemodified']['data'] = array('#markup' => $this->formatDate($entity, 'timemodified', 'short'));
     return $row;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['name']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#url' => $uri);
     $row['source']['data'] = $entity->getSource() ? t('online') : t('offline');
     $row['grade_valuation_type']['data'] = $entity->getGradeValuationType();
     $row['grade_display_type']['data'] = $entity->getGradeDisplayType();
     $row['multiplicator']['data'] = $entity->getMultiplicator();
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['name']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#url' => $uri);
     $row['lowest']['data'] = $entity->getLowest();
     $row['highest']['data'] = $entity->getHighest();
     $row['pass']['data'] = $entity->getPass();
     $row['hidden']['data'] = $entity->getHidden();
     $row['locked']['data'] = $entity->getLocked();
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['name']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#url' => $uri);
     $row['display_name'] = $entity->getDisplayName();
     $row['grade_aggregation_type'] = $entity->getGradeAggregationType();
     $row['exclude_empty'] = $entity->getExcludeEmpty() ? t('Yes') : t('No');
     $row['drop_lowest'] = $entity->getDropLowest();
     $row['author']['data'] = array('#theme' => 'username', '#account' => $entity->getOwner());
     return $row + parent::buildRow($entity);
 }
 public function create(EntityInterface $entity)
 {
     if (!isset($entity->xmlsitemap)) {
         $entity->xmlsitemap = array();
         if ($entity->id() && ($link = $this->load($entity->getEntityTypeId(), $entity->id()))) {
             $entity->xmlsitemap = $link;
         }
     }
     $settings = xmlsitemap_link_bundle_load($entity->getEntityTypeId(), $entity->bundle());
     $uri = $entity->url();
     $entity->xmlsitemap += array('type' => $entity->getEntityTypeId(), 'id' => (string) $entity->id(), 'subtype' => $entity->bundle(), 'status' => $settings['status'], 'status_default' => $settings['status'], 'status_override' => 0, 'priority' => $settings['priority'], 'priority_default' => $settings['priority'], 'priority_override' => 0, 'changefreq' => isset($settings['changefreq']) ? $settings['changefreq'] : 0);
     $url = $entity->url();
     // The following values must always be checked because they are volatile.
     $entity->xmlsitemap['loc'] = $uri;
     $entity->xmlsitemap['access'] = isset($url) && $entity->access('view', $this->anonymousUser);
     $language = $entity->language();
     $entity->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
     return $entity->xmlsitemap;
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\profile\Entity\ProfileInterface $entity */
     $langcode = $entity->language()->getId();
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : [];
     $uri->setOptions($options);
     $row['label'] = $entity->link();
     $row['type'] = $entity->getType();
     $row['owner']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
     $row['is_default'] = $entity->isDefault() ? $this->t('default') : $this->t('not default');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\node\NodeInterface $entity */
     $mark = array('#theme' => 'mark', '#mark_type' => node_mark($entity->id(), $entity->getChangedTime()));
     $langcode = $entity->language()->getId();
     $uri = $entity->urlInfo();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
     $uri->setOptions($options);
     $row['title']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#suffix' => ' ' . drupal_render($mark), '#url' => $uri);
     $row['type'] = node_get_type_label($entity);
     $row['author']['data'] = array('#theme' => 'username', '#account' => $entity->getOwner());
     $row['status'] = $entity->isPublished() ? $this->t('published') : $this->t('not published');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     $row['operations']['data'] = $this->buildOperations($entity);
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\profile\Entity\ProfileInterface $entity */
     $mark = ['#theme' => 'mark', '#mark_type' => node_mark($entity->id(), $entity->getChangedTime())];
     $langcode = $entity->language()->id;
     $uri = $entity->toUrl();
     $options = $uri->getOptions();
     $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : [];
     $uri->setOptions($options);
     $row['label']['data'] = ['#type' => 'link', '#title' => $entity->label(), '#suffix' => ' ' . $this->renderer->render($mark)] + $uri->toRenderArray();
     $row['type'] = $entity->getType()->id();
     $row['owner']['data'] = ['#theme' => 'username', '#account' => $entity->getOwner()];
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('not active');
     $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
     $language_manager = \Drupal::languageManager();
     if ($language_manager->isMultilingual()) {
         $row['language_name'] = $language_manager->getLanguageName($langcode);
     }
     $route_params = ['user' => $entity->getOwnerId(), 'type' => $entity->bundle(), 'profile' => $entity->id()];
     $links['edit'] = ['title' => t('Edit'), 'route_name' => 'entity.profile.edit_form', 'route_parameters' => $route_params];
     $links['delete'] = ['title' => t('Delete'), 'route_name' => 'entity.profile.delete_form', 'route_parameters' => $route_params];
     $row[] = ['data' => ['#type' => 'operations', '#links' => $links]];
     return $row + parent::buildRow($entity);
 }
Exemple #16
0
/**
 * Respond to creation of a new entity translation of a particular type.
 *
 * This hook runs once the entity translation has been stored. Note that hook
 * implementations may not alter the stored entity translation data.
 *
 * @param \Drupal\Core\Entity\EntityInterface $translation
 *   The entity object of the translation just stored.
 *
 * @ingroup entity_crud
 * @see hook_entity_translation_insert()
 */
function hook_ENTITY_TYPE_translation_insert(\Drupal\Core\Entity\EntityInterface $translation)
{
    $variables = array('@language' => $translation->language()->name, '@label' => $translation->getUntranslated()->label());
    \Drupal::logger('example')->notice('The @language translation of @label has just been stored.', $variables);
}
Exemple #17
0
 /**
  * Updates the form language to reflect any change to the entity language.
  *
  * There are use cases for modules to act both before and after form language
  * being updated, thus the update is performed through an entity builder
  * callback, which allows to support both cases.
  *
  * @param string $entity_type_id
  *   The entity type identifier.
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity updated with the submitted values.
  * @param array $form
  *   The complete form array.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @see \Drupal\Core\Entity\ContentEntityForm::form()
  */
 public function updateFormLangcode($entity_type_id, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     // Update the form language as it might have changed.
     if ($this->isDefaultFormLangcode($form_state)) {
         $langcode = $entity->language()->getId();
         $form_state->set('langcode', $langcode);
     }
 }
 /**
  * Build all necessary things for child form (form state, etc.).
  *
  * @param \Drupal\Core\Entity\EntityFormInterface $controller
  *   Entity form controller for child form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   Parent form state object.
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   Entity object.
  * @param string $operation
  *   Operation that is to be performed in inline form.
  *
  * @return \Drupal\Core\Form\FormStateInterface
  *   Child form state object.
  */
 public static function buildChildFormState(EntityFormInterface $controller, FormStateInterface $form_state, EntityInterface $entity, $operation)
 {
     $child_form_state = new FormState();
     $child_form_state->addBuildInfo('callback_object', $controller);
     $child_form_state->addBuildInfo('base_form_id', $controller->getBaseFormID());
     $child_form_state->addBuildInfo('form_id', $controller->getFormID());
     $child_form_state->addBuildInfo('args', array());
     // Copy values to child form.
     $child_form_state->setUserInput($form_state->getUserInput());
     $child_form_state->setValues($form_state->getValues());
     $child_form_state->setStorage($form_state->getStorage());
     $child_form_state->set('form_display', entity_get_form_display($entity->getEntityTypeId(), $entity->bundle(), $operation));
     // Since some of the submit handlers are run, redirects need to be disabled.
     $child_form_state->disableRedirect();
     // When a form is rebuilt after Ajax processing, its #build_id and #action
     // should not change.
     // @see drupal_rebuild_form()
     $rebuild_info = $child_form_state->getRebuildInfo();
     $rebuild_info['copy']['#build_id'] = TRUE;
     $rebuild_info['copy']['#action'] = TRUE;
     $child_form_state->setRebuildInfo($rebuild_info);
     $child_form_state->set('inline_entity_form', $form_state->get('inline_entity_form'));
     $child_form_state->set('langcode', $entity->language()->getId());
     $child_form_state->set('field', $form_state->get('field'));
     $child_form_state->setTriggeringElement($form_state->getTriggeringElement());
     $child_form_state->setSubmitHandlers($form_state->getSubmitHandlers());
     return $child_form_state;
 }
Exemple #19
0
 /**
  * Calculates a bulk form key.
  *
  * This generates a key that is used as the checkbox return value when
  * submitting a bulk form. This key allows the entity for the row to be loaded
  * totally independently of the executed view row.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity to calculate a bulk form key for.
  * @param bool $use_revision
  *   Whether the revision id should be added to the bulk form key. This should
  *   be set to TRUE only if the view is listing entity revisions.
  *
  * @return string
  *   The bulk form key representing the entity's id, language and revision (if
  *   applicable) as one string.
  *
  * @see self::loadEntityFromBulkFormKey()
  */
 protected function calculateEntityBulkFormKey(EntityInterface $entity, $use_revision)
 {
     $key_parts = [$entity->language()->getId(), $entity->id()];
     if ($entity instanceof RevisionableInterface && $use_revision) {
         $key_parts[] = $entity->getRevisionId();
     }
     return implode('-', $key_parts);
 }
 /**
  * {@inheritdoc}
  */
 public function retranslate(EntityInterface $entity, $langcode = NULL)
 {
     $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->getId();
     foreach ($entity->getTranslationLanguages() as $langcode => $language) {
         $this->manager->getTranslationMetadata($entity->getTranslation($langcode))->setOutdated($langcode != $updated_langcode);
     }
 }
Exemple #21
0
 /**
  * {@inheritdoc}
  */
 public function getFormLangcode(FormStateInterface $form_state)
 {
     return $this->entity->language()->id;
 }
 /**
  * {@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;
 }
 /**
  * Check if the default revision for the given entity is published.
  *
  * The default revision is the same as the entity retrieved by "default" from
  * the storage handler. If the entity is translated, use the default revision
  * of the same language as the given entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity being saved.
  *
  * @return bool
  *   TRUE if the default revision is published. FALSE otherwise.
  */
 protected function isDefaultRevisionPublished(EntityInterface $entity)
 {
     $storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
     $default_revision = $storage->load($entity->id());
     // Ensure we are comparing the same translation as the current entity.
     if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) {
         // If there is no translation, then there is no default revision and is
         // therefore not published.
         if (!$default_revision->hasTranslation($entity->language()->getId())) {
             return FALSE;
         }
         $default_revision = $default_revision->getTranslation($entity->language()->getId());
     }
     return $default_revision && $default_revision->moderation_state->entity->isPublishedState();
 }
Exemple #24
0
 /**
  * Calculates a bulk form key.
  *
  * This generates a key that is used as the checkbox return value when
  * submitting a bulk form. This key allows the entity for the row to be loaded
  * totally independently of the executed view row.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity to calculate a bulk form key for.
  * @param bool $use_revision
  *   Whether the revision id should be added to the bulk form key. This should
  *   be set to TRUE only if the view is listing entity revisions.
  *
  * @return string
  *   The bulk form key representing the entity's id, language and revision (if
  *   applicable) as one string.
  *
  * @see self::loadEntityFromBulkFormKey()
  */
 protected function calculateEntityBulkFormKey(EntityInterface $entity, $use_revision)
 {
     $key_parts = [$entity->language()->getId(), $entity->id()];
     if ($entity instanceof RevisionableInterface && $use_revision) {
         $key_parts[] = $entity->getRevisionId();
     }
     // An entity ID could be an arbitrary string (although they are typically
     // numeric). JSON then Base64 encoding ensures the bulk_form_key is
     // safe to use in HTML, and that the key parts can be retrieved.
     $key = json_encode($key_parts);
     return base64_encode($key);
 }
Exemple #25
0
 /**
  * {@inheritdoc}
  */
 public function getFormLangcode(array &$form_state)
 {
     return $this->entity->language()->id;
 }
 /**
  * {@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;
 }