예제 #1
0
 /**
  * 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
0
 /**
  * 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;
 }
 /**
  * {@inheritdoc}
  */
 protected function buildDeleteRevisionLink(EntityInterface $entity_revision)
 {
     if ($entity_revision->hasLinkTemplate('revision-delete')) {
         return ['title' => t('Delete'), 'url' => $entity_revision->toUrl('revision-delete')];
     }
 }
예제 #4
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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;
 }