Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     if (stristr($text, 'data-entity-type="file"') !== FALSE) {
         $dom = Html::load($text);
         $xpath = new \DOMXPath($dom);
         $processed_uuids = array();
         foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
             $uuid = $node->getAttribute('data-entity-uuid');
             // If there is a 'src' attribute, set it to the file entity's current
             // URL. This ensures the URL works even after the file location changes.
             if ($node->hasAttribute('src')) {
                 $file = $this->entityManager->loadEntityByUuid('file', $uuid);
                 if ($file) {
                     $node->setAttribute('src', file_url_transform_relative(file_create_url($file->getFileUri())));
                 }
             }
             // Only process the first occurrence of each file UUID.
             if (!isset($processed_uuids[$uuid])) {
                 $processed_uuids[$uuid] = TRUE;
                 $file = $this->entityManager->loadEntityByUuid('file', $uuid);
                 if ($file) {
                     $result->addCacheTags($file->getCacheTags());
                 }
             }
         }
         $result->setProcessedText(Html::serialize($dom));
     }
     return $result;
 }
Ejemplo n.º 2
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.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getContextValue()
 {
     if (!$this->contextValue) {
         $entity_type_id = substr($this->contextDefinition->getDataType(), 7);
         $this->contextValue = $this->entityManager->loadEntityByUuid($entity_type_id, $this->uuid);
     }
     return $this->contextValue;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function resolve(NormalizerInterface $normalizer, $data, $entity_type)
 {
     // The normalizer is what knows the specification of the data being
     // deserialized. If it can return a UUID from that data, and if there's an
     // entity with that UUID, then return its ID.
     if ($normalizer instanceof UuidReferenceInterface && ($uuid = $normalizer->getUuid($data))) {
         if ($entity = $this->entityManager->loadEntityByUuid($entity_type, $uuid)) {
             return $entity->id();
         }
     }
     return NULL;
 }
Ejemplo n.º 5
0
 /**
  * Loads the block content entity of the block.
  *
  * @return \Drupal\block_content\BlockContentInterface|null
  *   The block content entity.
  */
 protected function getEntity()
 {
     $uuid = $this->getDerivativeId();
     if (!isset($this->blockContent)) {
         $this->blockContent = $this->entityManager->loadEntityByUuid('block_content', $uuid);
     }
     return $this->blockContent;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $uuid = $this->getDerivativeId();
     if ($block = $this->entityManager->loadEntityByUuid('block_content', $uuid)) {
         return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
     } else {
         return array('#markup' => $this->t('Block with uuid %uuid does not exist. <a href="!url">Add custom block</a>.', array('%uuid' => $uuid, '!url' => $this->urlGenerator->generate('block_content.add_page'))), '#access' => $this->account->hasPermission('administer blocks'));
     }
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     if (stristr($text, 'data-entity-type="file"') !== FALSE) {
         $dom = Html::load($text);
         $xpath = new \DOMXPath($dom);
         $processed_uuids = array();
         foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
             $uuid = $node->getAttribute('data-entity-uuid');
             // Only process the first occurrence of each file UUID.
             if (!isset($processed_uuids[$uuid])) {
                 $processed_uuids[$uuid] = TRUE;
                 $file = $this->entityManager->loadEntityByUuid('file', $uuid);
                 if ($file) {
                     $result->addCacheTags($file->getCacheTags());
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function findMissingContentDependencies()
 {
     $content_dependencies = array();
     $missing_dependencies = array();
     foreach ($this->activeStorage->readMultiple($this->activeStorage->listAll()) as $config_data) {
         if (isset($config_data['dependencies']['content'])) {
             $content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['content']);
         }
     }
     foreach (array_unique($content_dependencies) as $content_dependency) {
         // Format of the dependency is entity_type:bundle:uuid.
         list($entity_type, $bundle, $uuid) = explode(':', $content_dependency, 3);
         if (!$this->entityManager->loadEntityByUuid($entity_type, $uuid)) {
             $missing_dependencies[$uuid] = array('entity_type' => $entity_type, 'bundle' => $bundle, 'uuid' => $uuid);
         }
     }
     return $missing_dependencies;
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function loadEntityByUuid($entity_type_id, $uuid)
 {
     return $this->entityManager->loadEntityByUuid($entity_type_id, $uuid);
 }