Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function applies($definition, $name, Route $route)
 {
     if (!empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) {
         $entity_type = substr($definition['type'], strlen('entity:'));
         return $this->entityManager->hasDefinition($entity_type);
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function applies($definition, $name, Route $route)
 {
     if (!empty($definition['type']) && strpos($definition['type'], 'entity_revision:') === 0) {
         $entity_type_id = substr($definition['type'], strlen('entity:'));
         if (strpos($definition['type'], '{') !== FALSE) {
             $entity_type_slug = substr($entity_type_id, 1, -1);
             return $name != $entity_type_slug && in_array($entity_type_slug, $route->compile()->getVariables(), TRUE);
         }
         return $this->entityManager->hasDefinition($entity_type_id);
     }
     return FALSE;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $name = '')
 {
     $this->page = $page;
     $this->staticContext = $this->page->getStaticContext($name);
     // Allow the condition to add to the form.
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => isset($this->staticContext['label']) ? $this->staticContext['label'] : '', '#required' => TRUE];
     $form['machine_name'] = ['#type' => 'machine_name', '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'contextExists'], 'source' => ['label']], '#default_value' => $name];
     $form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $this->entityManager->getEntityTypeLabels(TRUE), '#limit_validation_errors' => array(array('entity_type')), '#submit' => ['::rebuildSubmit'], '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::updateEntityType', 'wrapper' => 'add-static-context-wrapper', 'method' => 'replace')];
     $entity = NULL;
     if ($form_state->hasValue('entity_type')) {
         $entity_type = $form_state->getValue('entity_type');
         if ($this->staticContext['value']) {
             $entity = $this->entityManager->loadEntityByUuid($entity_type, $this->staticContext['value']);
         }
     } elseif (!empty($this->staticContext['type'])) {
         list(, $entity_type) = explode(':', $this->staticContext['type']);
         $entity = $this->entityManager->loadEntityByUuid($entity_type, $this->staticContext['value']);
     } elseif ($this->entityManager->hasDefinition('node')) {
         $entity_type = 'node';
     } else {
         $entity_type = 'user';
     }
     $form['entity_type']['#default_value'] = $entity_type;
     $form['selection'] = ['#type' => 'entity_autocomplete', '#prefix' => '<div id="add-static-context-wrapper">', '#suffix' => '</div>', '#required' => TRUE, '#target_type' => $entity_type, '#default_value' => $entity, '#title' => $this->t('Select entity')];
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitButtonText(), '#button_type' => 'primary'];
     return $form;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function remove()
 {
     parent::remove();
     if ($this->entityManager->hasDefinition('block')) {
         $plugin_id = 'views_block:' . $this->view->storage->id() . '-' . $this->display['id'];
         foreach ($this->entityManager->getStorage('block')->loadByProperties(['plugin' => $plugin_id]) as $block) {
             $block->delete();
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function hasDefinition($plugin_id)
 {
     return $this->entityManager->hasDefinition($plugin_id);
 }