當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityInterface::language方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\EntityInterface::language方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface::language方法的具體用法?PHP EntityInterface::language怎麽用?PHP EntityInterface::language使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\EntityInterface的用法示例。


在下文中一共展示了EntityInterface::language方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildChildFormState

  /**
   * 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;
  }
開發者ID:joebachana,項目名稱:usatne,代碼行數:59,代碼來源:EntityInlineForm.php

示例2: getTranslationFromContext

 /**
  * {@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;
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:31,代碼來源:EntityRepository.php

示例3: access

 /**
  * {@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();
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:29,代碼來源:EntityAccessControlHandler.php

示例4: retranslate

 /**
  * {@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;
     }
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:11,代碼來源:ContentTranslationHandler.php

示例5: assertNoEntityAlias

 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);
 }
開發者ID:AllieRays,項目名稱:debugging-drupal-8,代碼行數:8,代碼來源:PathautoTestHelperTrait.php

示例6: doExecute

 /**
  * 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);
 }
開發者ID:Progressable,項目名稱:openway8,代碼行數:18,代碼來源:EntityPathAliasCreate.php

示例7: buildRow

 /**
  * {@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);
 }
開發者ID:dakala,項目名稱:gradebook,代碼行數:14,代碼來源:GradeScaleListBuilder.php

示例8: buildRow

 /**
  * @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;
 }
開發者ID:bonrita,項目名稱:moodle,代碼行數:16,代碼來源:CourseListBuilder.php

示例9: buildRow

 /**
  * {@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);
 }
開發者ID:dakala,項目名稱:gradebook,代碼行數:17,代碼來源:GradeItemListBuilder.php

示例10: buildRow

 /**
  * {@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);
 }
開發者ID:dakala,項目名稱:gradebook,代碼行數:18,代碼來源:GradeItemDataListBuilder.php

示例11: buildRow

 /**
  * {@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);
 }
開發者ID:dakala,項目名稱:gradebook,代碼行數:18,代碼來源:GradeCategoryListBuilder.php

示例12: create

 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;
 }
開發者ID:jeroenos,項目名稱:jeroenos_d8.mypressonline.com,代碼行數:19,代碼來源:XmlSitemapLinkStorage.php

示例13: buildRow

 /**
  * {@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);
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:23,代碼來源:ProfileListBuilder.php

示例14: buildRow

 /**
  * {@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);
 }
開發者ID:ravindrasingh22,項目名稱:Drupal-8-rc,代碼行數:24,代碼來源:NodeListBuilder.php

示例15: buildRow

 /**
  * {@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);
 }
開發者ID:darrylri,項目名稱:protovbmwmo,代碼行數:27,代碼來源:ProfileListBuilder.php


注:本文中的Drupal\Core\Entity\EntityInterface::language方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。