예제 #1
0
 /**
  * Tests expandDependencies() when no variants exist and there are no static
  * (non-variant) dependencies.
  *
  * @covers ::expandDependencies
  */
 public function testExpandDependenciesNoVariantsOrStaticDependencies()
 {
     $this->query->method('execute')->willReturn([]);
     $dependencies = ['required' => ['d6_node:*', 'd6_node_revision:*']];
     $dependencies = $this->storage->expandDependencies($dependencies);
     $this->assertSame([], $dependencies['required']);
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * Helper method to execute an item query.
  *
  * @param \Drupal\Core\Entity\Query\QueryInterface $query
  *   The query to execute.
  * @param int $limit
  *   (optional) The number of items to return.
  *
  * @return \Drupal\aggregator\ItemInterface[]
  *   An array of the feed items.
  */
 protected function executeFeedItemQuery(QueryInterface $query, $limit)
 {
     $query->sort('timestamp', 'DESC')->sort('iid', 'DESC');
     if (!empty($limit)) {
         $query->pager($limit);
     }
     return $this->loadMultiple($query->execute());
 }
 /**
  * {@inheritdoc}
  */
 public function getButtons()
 {
     $buttons = array();
     if ($ids = $this->embedButtonQuery->execute()) {
         $embed_buttons = EmbedButton::loadMultiple($ids);
         foreach ($embed_buttons as $embed_button) {
             $buttons[$embed_button->id()] = $this->getButton($embed_button);
         }
     }
     return $buttons;
 }
예제 #5
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();
 }
 /**
  * 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');
         }
     }
 }
 /**
  * Helper function to add expectations to the mock entity query object.
  *
  * @param int $count
  *   The number of deduplications to be set up.
  */
 protected function entityQueryExpects($count)
 {
     $this->entityQuery->expects($this->exactly($count + 1))->method('condition')->will($this->returnValue($this->entityQuery));
     $this->entityQuery->expects($this->exactly($count + 1))->method('count')->will($this->returnValue($this->entityQuery));
     $this->entityQuery->expects($this->exactly($count + 1))->method('execute')->will($this->returnCallback(function () use(&$count) {
         return $count--;
     }));
 }
 /**
  * Tests the getDefaultSearchPage() method when the default is inactive.
  */
 public function testGetDefaultSearchPageWithInactiveDefault()
 {
     $this->query->expects($this->once())->method('condition')->with('status', TRUE)->will($this->returnValue($this->query));
     $this->query->expects($this->once())->method('execute')->will($this->returnValue(array('test' => 'test')));
     $config = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('get')->with('default_page')->will($this->returnValue('other_test'));
     $this->configFactory->expects($this->once())->method('get')->with('search.settings')->will($this->returnValue($config));
     $this->assertSame('test', $this->searchPageRepository->getDefaultSearchPage());
 }
 /**
  * Returns a build array for the solution releases overview page.
  *
  * @param \Drupal\rdf_entity\RdfInterface $rdf_entity
  *   The solution rdf entity.
  *
  * @return array
  *   The build array for the page.
  */
 public function overview(RdfInterface $rdf_entity)
 {
     $view_builder = $this->entityTypeManager()->getViewBuilder('rdf_entity');
     $ids = $this->queryFactory->get('rdf_entity', 'AND')->condition('rid', 'asset_release')->condition('field_isr_is_version_of', $rdf_entity->id())->sort('field_isr_creation_date', 'DESC')->execute();
     $releases = [];
     /** @var \Drupal\rdf_entity\RdfInterface $release */
     foreach (Rdf::loadMultiple($ids) as $release) {
         $releases[] = $view_builder->view($release, 'compact');
     }
     return ['#theme' => 'asset_release_releases_download', '#releases' => $releases];
 }
 /**
  * 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);
         }
     }
 }
예제 #11
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;
 }
 /**
  * @covers ::save()
  * @covers ::doSave()
  *
  * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException
  * @expectedExceptionMessage when this entity already exists with UUID
  */
 public function testSaveChangedUuid()
 {
     $config_object = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config_object->expects($this->atLeastOnce())->method('isNew')->will($this->returnValue(FALSE));
     $config_object->expects($this->never())->method('save');
     $config_object->expects($this->exactly(2))->method('get')->will($this->returnValueMap(array(array('', array('id' => 'foo')), array('id', 'foo'))));
     $this->cacheBackend->expects($this->never())->method('invalidateTags');
     $this->configFactory->expects($this->at(1))->method('loadMultiple')->with(array('the_config_prefix.foo'))->will($this->returnValue(array()));
     $this->configFactory->expects($this->at(2))->method('loadMultiple')->with(array('the_config_prefix.foo'))->will($this->returnValue(array($config_object)));
     $this->configFactory->expects($this->once())->method('get')->with('the_config_prefix.foo')->will($this->returnValue($config_object));
     $this->configFactory->expects($this->never())->method('rename')->will($this->returnValue($config_object));
     $this->moduleHandler->expects($this->exactly(2))->method('getImplementations')->will($this->returnValue(array()));
     $this->entityQuery->expects($this->once())->method('condition')->will($this->returnSelf());
     $this->entityQuery->expects($this->once())->method('execute')->will($this->returnValue(array('foo')));
     $entity = $this->getMockEntity(array('id' => 'foo'));
     $entity->set('uuid', 'baz');
     $this->entityStorage->save($entity);
 }
예제 #14
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);
         }
     }
 }
예제 #15
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;
 }
예제 #17
0
 /**
  * {@inheritdoc}
  */
 protected function processStubRow(Row $row)
 {
     parent::processStubRow($row);
     $stub_commented_entity_type = $row->getDestinationProperty('entity_type');
     // While parent::getEntity() fills the bundle property for stub entities
     // if it's still empty, here we must also make sure entity_id/entity_type
     // are filled (so $comment->getCommentedEntity() always returns a value).
     if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) {
         // Fill stub entity id. Any id will do, as long as it exists.
         $entity_type = $this->entityManager->getDefinition($stub_commented_entity_type);
         $id_key = $entity_type->getKey('id');
         $result = $this->entityQuery->get($stub_commented_entity_type)->range(0, 1)->execute();
         if ($result) {
             $this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result);
             $row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]);
         } else {
             throw new MigrateException(t('Could not find parent entity to use for comment %id', ['%id' => implode(':', $row->getSourceIdValues())]), MigrationInterface::MESSAGE_ERROR);
         }
     }
     $row->setDestinationProperty('entity_id', $this->stubCommentedEntityIds[$stub_commented_entity_type]);
     $row->setDestinationProperty('entity_type', $stub_commented_entity_type);
     $row->setDestinationProperty('created', REQUEST_TIME);
     $row->setDestinationProperty('changed', REQUEST_TIME);
 }
예제 #18
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');
}
예제 #19
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);
 }
예제 #20
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);
     }
 }
예제 #21
0
 /**
  * Tests getVariantIds() when no variants exist and there are no static
  * (non-variant) dependencies.
  *
  * @covers ::getVariantIds
  */
 public function testGetVariantIdsNoVariantsOrStaticDependencies()
 {
     $this->query->method('execute')->willReturn([]);
     $ids = $this->storage->getVariantIds(['d6_node:*', 'd6_node_revision:*']);
     $this->assertSame([], $ids);
 }
예제 #22
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');
     }
 }
예제 #23
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'
   );
 }