当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityInterface::toUrl方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::toUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::toUrl方法的具体用法?PHP EntityInterface::toUrl怎么用?PHP EntityInterface::toUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityInterface的用法示例。


在下文中一共展示了EntityInterface::toUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCancelUrl

 /**
  * {@inheritdoc}
  */
 public function getCancelUrl()
 {
     if ($this->revision->getEntityType()->hasLinkTemplate('version-history')) {
         return $this->revision->toUrl('version-history');
     }
     return $this->revision->toUrl();
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:10,代码来源:RevisionRevertForm.php

示例2: save

 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $this->entity->setNewRevision();
     }
     $insert = $this->entity->isNew();
     $this->entity->save();
     $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
     $logger = $this->logger($this->entity->id());
     $bundle_entity = $this->getBundleEntity();
     $t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->label()];
     if ($insert) {
         $logger->notice('@type: added %info.', $context);
         drupal_set_message($this->t('@type %info has been created.', $t_args));
     } else {
         $logger->notice('@type: updated %info.', $context);
         drupal_set_message($this->t('@type %info has been updated.', $t_args));
     }
     if ($this->entity->id()) {
         $form_state->setValue('id', $this->entity->id());
         $form_state->set('id', $this->entity->id());
         if ($this->entity->getEntityType()->hasLinkTemplate('collection')) {
             $form_state->setRedirectUrl($this->entity->toUrl('collection'));
         } else {
             $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
         }
     } else {
         // In the unlikely case something went wrong on save, the entity will be
         // rebuilt and entity form redisplayed.
         drupal_set_message($this->t('The entity could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:37,代码来源:RevisionableContentEntityForm.php

示例3: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\conference_sessions\Entity\RoomTypeInterface $entity */
     $product_type = RoomType::load($entity->bundle());
     $row['title']['data'] = ['#type' => 'link', '#title' => $entity->label()] + $entity->toUrl()->toRenderArray();
     $row['type'] = $product_type->label();
     $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished');
     return $row + parent::buildRow($entity);
 }
开发者ID:mglaman,项目名称:drupalcamp-base,代码行数:12,代码来源:RoomListBuilder.php

示例4: 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

示例5: 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

示例6: 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

示例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['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

示例8: 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

示例9: 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

示例10: getTestToUrl

 /**
  * Creates a \Drupal\Core\Url object based on the entity and link template.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The test entity.
  * @param string $link_template
  *   The link template.
  * @param string $langcode
  *   The langcode.
  *
  * @return \Drupal\Core\Url
  *   The URL for this entity's link template.
  */
 protected function getTestToUrl(EntityInterface $entity, $link_template, array $options = [], $langcode = NULL)
 {
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->any())->method('getLinkTemplates')->will($this->returnValue(array('edit-form' => 'test_entity_type.edit')));
     if ($langcode) {
         $entity->langcode = $langcode;
     }
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($entity_type));
     // If no link template is given, call without a value to test the default.
     if ($link_template) {
         $uri = $entity->toUrl($link_template, $options);
     } else {
         if ($entity instanceof ConfigEntityInterface) {
             $uri = $entity->toUrl('edit-form', $options);
         } else {
             $uri = $entity->toUrl('canonical', $options);
         }
     }
     return $uri;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:33,代码来源:EntityUrlTest.php

示例11: buildDeleteRevisionLink

 /**
  * {@inheritdoc}
  */
 protected function buildDeleteRevisionLink(EntityInterface $entity_revision)
 {
     if ($entity_revision->hasLinkTemplate('revision-delete')) {
         return ['title' => t('Delete'), 'url' => $entity_revision->toUrl('revision-delete')];
     }
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:9,代码来源:RevisionOverviewController.php

示例12: patchEntity

  /**
   * Patches an existing entity using the passed in (modified) entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The updated entity to send.
   * @param string[] $read_only_fields
   *   Names of the fields that are read-only, in validation order.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The account to use for serialization.
   * @param string $format
   *   A serialization format.
   * @param string $mime_type
   *   The MIME type corresponding to the specified serialization format.
   */
  protected function patchEntity(EntityInterface $entity, array $read_only_fields, AccountInterface $account, $format, $mime_type) {
    $serializer = $this->container->get('serializer');

    $url = $entity->toUrl()->setRouteParameter('_format', $this->defaultFormat);
    $context = ['account' => $account];
    // Certain fields are always read-only, others this user simply is not
    // allowed to modify. For all of them, ensure they are not serialized, else
    // we'll get a 403 plus an error message.
    for ($i = 0; $i < count($read_only_fields); $i++) {
      $field = $read_only_fields[$i];

      $normalized = $serializer->normalize($entity, $format, $context);
      if ($format !== 'hal_json') {
        // The default normalizer always keeps fields, even if they are unset
        // here because they should be omitted during a PATCH request. Therefore
        // manually strip them
        // @see \Drupal\Core\Entity\ContentEntityBase::__unset()
        // @see \Drupal\serialization\Normalizer\EntityNormalizer::normalize()
        // @see \Drupal\hal\Normalizer\ContentEntityNormalizer::normalize()
        $read_only_fields_so_far = array_slice($read_only_fields, 0, $i);
        $normalized = array_diff_key($normalized, array_flip($read_only_fields_so_far));
      }
      $serialized = $serializer->serialize($normalized, $format, $context);

      $this->httpRequest($url, 'PATCH', $serialized, $mime_type);
      $this->assertResponse(403);
      $this->assertResponseBody('{"message":"Access denied on updating field \\u0027' . $field . '\\u0027."}');

      if ($format === 'hal_json') {
        // We've just tried with this read-only field, now unset it.
        $entity->set($field, NULL);
      }
    }

    // Finally, with all read-only fields unset, the request should succeed.
    $normalized = $serializer->normalize($entity, $format, $context);
    if ($format !== 'hal_json') {
      $normalized = array_diff_key($normalized, array_combine($read_only_fields, $read_only_fields));
    }
    $serialized = $serializer->serialize($normalized, $format, $context);

    // Try first without CSRF token which should fail.
    $this->httpRequest($url, 'PATCH', $serialized, $mime_type, FALSE);
    $this->assertResponse(403);
    $this->assertRaw('X-CSRF-Token request header is missing');
    // Then try with an invalid CSRF token.
    $this->httpRequest($url, 'PATCH', $serialized, $mime_type, 'invalid-csrf-token');
    $this->assertResponse(403);
    $this->assertRaw('X-CSRF-Token request header is invalid');
    // Then try with CSRF token.
    $this->httpRequest($url, 'PATCH', $serialized, $mime_type);
    $this->assertResponse(200);
  }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:67,代码来源:UpdateTest.php

示例13: getReadUrl

 /**
  * Gets the read URL object for the entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity to get the URL for.
  * @param string $format
  *   The format to request the entity in.
  * @param string $entity_id
  *   The entity ID to use in the URL, defaults to the entity's ID if know
  *   given.
  *
  * @return \Drupal\Core\Url
  *   The Url object.
  */
 protected function getReadUrl(EntityInterface $entity, $format = NULL, $entity_id = NULL)
 {
     if (!$format) {
         $format = $this->defaultFormat;
     }
     if (!$entity_id) {
         $entity_id = $entity->id();
     }
     $entity_type = $entity->getEntityTypeId();
     if ($entity->hasLinkTemplate('canonical')) {
         $url = $entity->toUrl('canonical');
     } else {
         $route_name = 'rest.entity.' . $entity_type . ".GET.";
         // If testing unsupported format don't use the format to construct route
         // name. This would give a RouteNotFoundException.
         if ($format == 'wrongformat') {
             $route_name .= $this->defaultFormat;
         } else {
             $route_name .= $format;
         }
         $url = Url::fromRoute($route_name);
     }
     $url->setRouteParameter($entity_type, $entity_id);
     $url->setRouteParameter('_format', $format);
     return $url;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:40,代码来源:ReadTest.php

示例14: getCancelUrl

 /**
  * {@inheritdoc}
  */
 public function getCancelUrl() {
   return $this->entity->toUrl();
 }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:6,代码来源:FlagConfirmFormBase.php

示例15: buildPath

 /**
  * Builds the path string used in the match array.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *    The matched entity.
  *
  * @return string
  *   The URL for this entity.
  */
 protected function buildPath($entity) {
   return $entity->toUrl()->toString();
 }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:12,代码来源:EntityMatcher.php


注:本文中的Drupal\Core\Entity\EntityInterface::toUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。