本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::hasLinkTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::hasLinkTemplate方法的具体用法?PHP EntityInterface::hasLinkTemplate怎么用?PHP EntityInterface::hasLinkTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::hasLinkTemplate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actions
/**
* Returns an array of supported actions for the current entity form.
*
* @todo Consider introducing a 'preview' action here, since it is used by
* many entity types.
*/
protected function actions(array $form, FormStateInterface $form_state)
{
// @todo Rename the action key from submit to save.
$actions['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#validate' => array(array($this, 'validate')), '#submit' => array(array($this, 'submit'), array($this, 'save')));
if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('delete-form')) {
$route_info = $this->entity->urlInfo('delete-form');
if ($this->getRequest()->query->has('destination')) {
$query = $route_info->getOption('query');
$query['destination'] = $this->getRequest()->query->get('destination');
$route_info->setOption('query', $query);
}
$actions['delete'] = array('#type' => 'link', '#title' => $this->t('Delete'), '#access' => $this->entity->access('delete'), '#attributes' => array('class' => array('button', 'button--danger')));
$actions['delete'] += $route_info->toRenderArray();
}
return $actions;
}
示例2: actions
/**
* Returns an array of supported actions for the current entity form.
*
* @todo Consider introducing a 'preview' action here, since it is used by
* many entity types.
*/
protected function actions(array $form, FormStateInterface $form_state)
{
// @todo Consider renaming the action key from submit to save. The impacts
// are hard to predict. For example, see
// \Drupal\language\Element\LanguageConfiguration::processLanguageConfiguration().
$actions['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#validate' => array('::validate'), '#submit' => array('::submitForm', '::save'));
if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('delete-form')) {
$route_info = $this->entity->urlInfo('delete-form');
if ($this->getRequest()->query->has('destination')) {
$query = $route_info->getOption('query');
$query['destination'] = $this->getRequest()->query->get('destination');
$route_info->setOption('query', $query);
}
$actions['delete'] = array('#type' => 'link', '#title' => $this->t('Delete'), '#access' => $this->entity->access('delete'), '#attributes' => array('class' => array('button', 'button--danger')));
$actions['delete']['#url'] = $route_info;
}
return $actions;
}
示例3: buildDeleteRevisionLink
/**
* {@inheritdoc}
*/
protected function buildDeleteRevisionLink(EntityInterface $entity_revision)
{
if ($entity_revision->hasLinkTemplate('revision-delete')) {
return ['title' => t('Delete'), 'url' => $entity_revision->toUrl('revision-delete')];
}
}
示例4: getEntityUri
/**
* Constructs the entity URI.
*
* @param \Drupal\Core\Entity\EntityInterface
* The entity.
* @return string
* The entity URI.
*/
protected function getEntityUri(EntityInterface $entity)
{
// Some entity types don't provide a canonical link template, at least call
// out to ->url().
if ($entity->isNew() || !$entity->hasLinkTemplate('canonical')) {
return $entity->url('canonical', []);
}
$url = $entity->urlInfo('canonical', ['absolute' => TRUE]);
return $url->setRouteParameter('_format', 'hal_json')->toString();
}
示例5: 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;
}
示例6: getDefaultOperations
/**
* Gets this list's default operations.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity the operations are for.
*
* @return array
* The array structure is identical to the return value of
* self::getOperations().
*/
protected function getDefaultOperations(EntityInterface $entity)
{
$operations = array();
if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
$operations['edit'] = array('title' => $this->t('Edit'), 'weight' => 10, 'url' => $entity->urlInfo('edit-form'));
}
if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
$operations['delete'] = array('title' => $this->t('Delete'), 'weight' => 100, 'url' => $entity->urlInfo('delete-form'));
}
return $operations;
}