/**
  * Constructs a Drupal\entity_embed\Plugin\CKEditorPlugin\DrupalEntity object.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\Core\Entity\Query\QueryInterface $embed_button_query
  *   The entity query object for embed button.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $embed_button_query)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->embedButtonQuery = $embed_button_query;
     if (!empty($plugin_definition['embed_type_id'])) {
         $this->embedButtonQuery->condition('type_id', $plugin_definition['embed_type_id']);
     }
 }
Пример #2
0
 /**
  * Gets entity browser IDs that use routes.
  *
  * @return array
  *   Array of browser IDs.
  */
 protected function getBrowserIDsWithRoute()
 {
     // Get all display plugins which provides the type.
     $display_plugins = $this->displayManager->getDefinitions();
     $ids = array();
     foreach ($display_plugins as $id => $definition) {
         if (!empty($definition['uses_route'])) {
             $ids[$id] = $id;
         }
     }
     return $this->browserQuery->condition('status', TRUE)->condition("display", $ids, 'IN')->execute();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function buildPropertyQuery(QueryInterface $entity_query, array $values)
 {
     if (isset($values['name'])) {
         $entity_query->condition('name', $values['name'], 'LIKE');
         unset($values['name']);
     }
     parent::buildPropertyQuery($entity_query, $values);
 }
 /**
  * Implements \Drupal\aggregator\Plugin\ProcessorInterface::postProcess().
  *
  * Expires items from a feed depending on expiration settings.
  */
 public function postProcess(FeedInterface $feed)
 {
     $aggregator_clear = $this->configuration['items']['expire'];
     if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
         // Delete all items that are older than flush item timer.
         $age = REQUEST_TIME - $aggregator_clear;
         $result = $this->itemQuery->condition('fid', $feed->id())->condition('timestamp', $age, '<')->execute();
         if ($result) {
             $entities = $this->itemStorage->loadMultiple($result);
             $this->itemStorage->delete($entities);
         }
     }
 }
 /**
  * Removes existing registered identities from the query.
  *
  * @param \Drupal\Core\Entity\Query\QueryInterface $query
  *   The entity query to modify.
  */
 protected function removeDuplicateRegistrants(QueryInterface &$query)
 {
     if (!$this->eventMeta->duplicateRegistrantsAllowed()) {
         $entity_ids = [];
         $registrants = $this->eventMeta->getRegistrants($this->entityType->id());
         foreach ($registrants as $registrant) {
             $entity_ids[] = $registrant->getIdentityId()['entity_id'];
         }
         if ($entity_ids) {
             $query->condition($this->entityType->getKey('id'), $entity_ids, 'NOT IN');
         }
     }
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // Load the selected feed.
     if ($feed = $this->feedStorage->load($this->configuration['feed'])) {
         $result = $this->itemQuery->condition('fid', $feed->id())->range(0, $this->configuration['block_count'])->sort('timestamp', 'DESC')->sort('iid', 'DESC')->execute();
         if ($result) {
             // Only display the block if there are items to show.
             $items = $this->itemStorage->loadMultiple($result);
             $build['list'] = ['#theme' => 'item_list', '#items' => []];
             foreach ($items as $item) {
                 $build['list']['#items'][$item->id()] = ['#type' => 'link', '#url' => $item->urlInfo(), '#title' => $item->label()];
             }
             $build['more_link'] = ['#type' => 'more_link', '#url' => $feed->urlInfo(), '#attributes' => ['title' => $this->t("View this feed's recent news.")]];
             return $build;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $entity = $items->getEntity();
     /* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity */
     $bundle_entity = $this->entityTypeManager->getStorage($entity->getEntityType()->getBundleEntityType())->load($entity->bundle());
     if (!$this->moderationInformation->isModeratableEntity($entity)) {
         // @todo write a test for this.
         return $element + ['#access' => FALSE];
     }
     $options = $this->fieldDefinition->getFieldStorageDefinition()->getOptionsProvider($this->column, $entity)->getSettableOptions($this->currentUser);
     $default = $items->get($delta)->target_id ?: $bundle_entity->getThirdPartySetting('workbench_moderation', 'default_moderation_state', FALSE);
     /** @var \Drupal\workbench_moderation\ModerationStateInterface $default_state */
     $default_state = ModerationState::load($default);
     if (!$default || !$default_state) {
         throw new \UnexpectedValueException(sprintf('The %s bundle has an invalid moderation state configuration, moderation states are enabled but no default is set.', $bundle_entity->label()));
     }
     // @todo write a test for this.
     $from = $this->moderationStateTransitionEntityQuery->condition('stateFrom', $default)->execute();
     // Can always keep this one as is.
     $to[$default] = $default;
     // @todo write a test for this.
     $allowed = $bundle_entity->getThirdPartySetting('workbench_moderation', 'allowed_moderation_states', []);
     if ($from) {
         /* @var \Drupal\workbench_moderation\ModerationStateTransitionInterface $transition */
         foreach ($this->moderationStateTransitionStorage->loadMultiple($from) as $id => $transition) {
             $to_state = $transition->getToState();
             if ($this->currentUser->hasPermission('use ' . $id . ' transition') && in_array($to_state, $allowed, TRUE)) {
                 $to[$to_state] = $to_state;
             }
         }
     }
     $options = array_intersect_key($options, $to);
     // @todo write a test for this.
     $element += ['#access' => count($options), '#type' => 'select', '#options' => $options, '#default_value' => $default, '#published' => $default ? $default_state->isPublishedState() : FALSE];
     if ($this->currentUser->hasPermission($this->getAdminPermission($entity->getEntityType())) && count($options)) {
         // Use the dropbutton.
         $element['#process'][] = [get_called_class(), 'processActions'];
         // Don't show in sidebar/body.
         $element['#access'] = FALSE;
     } else {
         // Place the field as a details element in the advanced tab-set in e.g.
         // the sidebar.
         $element = ['#type' => 'details', '#group' => 'advanced', '#open' => TRUE, '#weight' => -10, '#title' => t('Moderation state'), 'target_id' => $element];
     }
     return $element;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // Load the selected feed.
     if ($feed = $this->feedStorage->load($this->configuration['feed'])) {
         $result = $this->itemQuery->condition('fid', $feed->id())->range(0, $this->configuration['block_count'])->sort('timestamp', 'DESC')->sort('iid', 'DESC')->execute();
         $items = $this->itemStorage->loadMultiple($result);
         $more_link = array('#theme' => 'more_link', '#url' => 'aggregator/sources/' . $feed->id(), '#title' => t("View this feed's recent news."));
         $read_more = drupal_render($more_link);
         $rendered_items = array();
         foreach ($items as $item) {
             $aggregator_block_item = array('#theme' => 'aggregator_block_item', '#item' => $item);
             $rendered_items[] = drupal_render($aggregator_block_item);
         }
         // Only display the block if there are items to show.
         if (count($rendered_items) > 0) {
             $item_list = array('#theme' => 'item_list', '#items' => $rendered_items);
             return array('#children' => drupal_render($item_list) . $read_more);
         }
     }
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function match(ContactInterface $contact, $property = 'value')
 {
     $ids = array();
     $field = $this->field->getName();
     $needle = $contact->get($field)->{$property};
     if (!empty($needle)) {
         $this->query->condition('type', $contact->bundle());
         if ($contact->id()) {
             $this->query->condition('contact_id', $contact->id(), '<>');
         }
         if ($field instanceof FieldConfigInterface) {
             $field .= '.' . $property;
         }
         $this->query->condition($field, $needle, $this->getOperator($property));
         $ids = $this->query->execute();
     }
     // Get the score for this field/propery.
     $score = array($this->field->getName() . '.' . $property => $this->getScore($property));
     // Returning an array holding the score as value and the contact id as key.
     return array_fill_keys($ids, $score);
 }
 /**
  * Gets terms which matches some typed terms.
  *
  * @param string $tags_typed
  *   The full typed tags string.
  * @param array $vids
  *   An array of vocabulary IDs which
  * @param $tag_last
  *   The lasted typed tag.
  *
  * @return array
  *   Returns an array of matching terms.
  */
 protected function getMatchingTerms($tags_typed, array $vids, $tag_last)
 {
     $matches = array();
     $this->termEntityQuery->addTag('term_access');
     // Do not select already entered terms.
     if (!empty($tags_typed)) {
         $this->termEntityQuery->condition('name', $tags_typed, 'NOT IN');
     }
     // Select rows that match by term name.
     $tids = $this->termEntityQuery->condition('vid', $vids, 'IN')->condition('name', $tag_last, 'CONTAINS')->range(0, 10)->execute();
     $prefix = count($tags_typed) ? Tags::implode($tags_typed) . ', ' : '';
     if (!empty($tids)) {
         $terms = $this->entityManager->getStorage('taxonomy_term')->loadMultiple(array_keys($tids));
         foreach ($terms as $term) {
             // Term names containing commas or quotes must be wrapped in quotes.
             $name = Tags::encode($term->getName());
             $matches[] = array('value' => $prefix . $name, 'label' => String::checkPlain($term->getName()));
         }
         return $matches;
     }
     return $matches;
 }
Пример #11
0
 /**
  * Builds an entity query.
  *
  * @param \Drupal\Core\Entity\Query\QueryInterface $entity_query
  *   EntityQuery instance.
  * @param array $values
  *   An associative array of properties of the entity, where the keys are the
  *   property names and the values are the values those properties must have.
  */
 protected function buildPropertyQuery(QueryInterface $entity_query, array $values)
 {
     foreach ($values as $name => $value) {
         // Cast scalars to array so we can consistently use an IN condition.
         $entity_query->condition($name, (array) $value, 'IN');
     }
 }
Пример #12
0
 /**
  * Determines if there is any book nodes or not.
  *
  * @return bool
  *   TRUE if there are book nodes, FALSE otherwise.
  */
 protected function hasBookNodes()
 {
     $nodes = $this->entityQuery->condition('type', 'book')->accessCheck(FALSE)->range(0, 1)->execute();
     return !empty($nodes);
 }
Пример #13
0
 /**
  * Add conditions to a query to select updates to run.
  *
  * @param \Drupal\Core\Entity\Query\QueryInterface $query
  * @param string $condition_prefix
  *  String to attach to the beginning of all conditions if the base table is not updates.
  */
 protected function addActiveUpdateConditions(QueryInterface $query, $condition_prefix = '') {
   $query->condition($condition_prefix. 'update_timestamp', REQUEST_TIME, '<=');
   $query->condition($condition_prefix. 'type', $this->scheduled_update_type->id());
   $query->condition(
     $condition_prefix. 'status',
     [
       ScheduledUpdateInterface::STATUS_UNRUN,
       // @todo How to handle requeued items.
       //ScheduledUpdateInterface::STATUS_REQUEUED,
     ],
     'IN'
   );
 }
Пример #14
0
 /**
  * Builds an entity query.
  *
  * @param \Drupal\Core\Entity\Query\QueryInterface $entity_query
  *   EntityQuery instance.
  * @param array $values
  *   An associative array of properties of the entity, where the keys are the
  *   property names and the values are the values those properties must have.
  */
 protected function buildPropertyQuery(QueryInterface $entity_query, array $values)
 {
     foreach ($values as $name => $value) {
         $entity_query->condition($name, $value);
     }
 }
Пример #15
0
/**
 * Allows to alter $query used to list entities on specific entity type overview
 * pages.
 *
 * @see TMGMTEntityDefaultSourceUIController
 */
function hook_tmgmt_content_list_query_alter(QueryInterface $query)
{
    $query->condition('type', array('article', 'page'), 'IN');
}