/**
  * {@inheritdoc}
  */
 public function load()
 {
     // It is not possible to use the standard load method, because this needs
     // all field instance entities only for the given baseEntityType.
     $ids = \Drupal::entityQuery('field_instance_config')->condition('id', $this->baseEntityType . '.', 'STARTS_WITH')->execute();
     return $this->storage->loadMultiple($ids);
 }
コード例 #2
0
 /**
  * Tests creating a product via the admin.
  */
 function testAddProductAdmin()
 {
     $title = $this->randomMachineName();
     $store_ids = array_map(function ($store) {
         return $store->id();
     }, $this->stores);
     $this->drupalGet('admin/commerce/products');
     $this->clickLink('Add product');
     $product_variation_values = ['variations[form][inline_entity_form][sku][0][value]' => $this->randomMachineName(), 'variations[form][inline_entity_form][status][value]' => 1];
     $this->drupalPostForm(NULL, $product_variation_values, t('Create variation'));
     $edit = ['title[0][value]' => $title];
     foreach ($store_ids as $store_id) {
         $edit['stores[target_id][value][' . $store_id . ']'] = $store_id;
     }
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
     $result = \Drupal::entityQuery('commerce_product')->condition("title", $edit['title[0][value]'])->range(0, 1)->execute();
     $product_id = reset($result);
     $product = Product::load($product_id);
     $this->assertNotNull($product, 'The new product has been created in the database.');
     $this->assertText(t('The product @title has been successfully saved', ['@title' => $title]), 'Product success text is shown');
     $this->assertText($title, 'Created product name exists on this page.');
     $this->assertFieldValues($product->getStores(), $this->stores, 'Created product has the correct associated stores.');
     $this->assertFieldValues($product->getStoreIds(), $store_ids, 'Created product has the correct associated store ids.');
     // Assert that the frontend product page is displaying.
     $this->drupalGet('product/' . $product->id());
     $this->assertResponse(200);
     $this->assertText($product->getTitle(), 'Product title exists');
     // Test product variations
     $product_variation = \Drupal::entityQuery('commerce_product_variation')->condition("sku", $product_variation_values['variations[form][inline_entity_form][sku][0][value]'])->range(0, 1)->execute();
     $product_variation = ProductVariation::load(current($product_variation));
     $this->assertNotNull($product_variation, 'The new product variation has been created in the database.');
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'team_member')->sort('field_order', 'ASC');
     $nids = $query->execute();
     $nodes = node_load_multiple($nids);
     //$nodes = entity_load_multiple('node', $nids);
     $ind = 1;
     $output = '<div class="tabbable tabs-left tabcordion">
             <ul class="nav nav-tabs">';
     foreach ($nodes as $node) {
         $class = $ind == 1 ? 'active' : '';
         $output .= '<li class="' . $class . '"><a data-target="#team_member_tab' . $ind . '" data-toggle="tab">' . $node->title->value . '<span>' . $node->get('field_designation')->value . '</span></a></li>';
         $ind++;
     }
     $ind = 1;
     $output .= '</ul>
         <div class="tab-content">';
     foreach ($nodes as $node) {
         $class = $ind == 1 ? 'active' : '';
         if (is_object($node->field_image->entity)) {
             $path = $node->field_image->entity->getFileUri();
             $url = ImageStyle::load('person_picture')->buildUrl($path);
             $tab_content_html = '<div class="row"><div class="col-md-3"><img src="' . $url . '" alt=""></div><div class="col-md-9">' . $node->get('body')->value . '</div> </div>';
         } else {
             $tab_content_html = '<div>' . $node->get('body')->value . '</div>';
         }
         $output .= '<div class="tab-pane ' . $class . '" id="team_member_tab' . $ind . '"> ' . $tab_content_html . ' </div>';
         $ind++;
     }
     $output .= '</div>
       </div>';
     return array('#type' => 'markup', '#markup' => $output, '#attached' => array('library' => array('barney_river_utilities/tabcordion', 'barney_river_utilities/tabcordion_hook')));
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function validate($items, Constraint $constraint)
 {
     $bundles = $constraint->bundles;
     if (!($item = $items->first())) {
         return;
     }
     $field_name = $items->getFieldDefinition()->getName();
     /** @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $items->getEntity();
     $bundle = $entity->bundle();
     if (!in_array($bundle, $bundles)) {
         // The constraint does not apply to this bundle.
         return;
     }
     $bundle_key = $entity->getEntityType()->getKey('bundle');
     $entity_type_id = $entity->getEntityTypeId();
     $id_key = $entity->getEntityType()->getKey('id');
     $query = \Drupal::entityQuery($entity_type_id)->condition($field_name, $item->value)->condition($bundle_key, $bundles, 'IN');
     if (!empty($entity->id())) {
         $query->condition($id_key, $items->getEntity()->id(), '<>');
     }
     $value_taken = (bool) $query->range(0, 1)->count()->execute();
     if ($value_taken) {
         $this->context->addViolation($constraint->message, ['%value' => $item->value, '@entity_type' => $entity->getEntityType()->getLowercaseLabel(), '@field_name' => Unicode::strtolower($items->getFieldDefinition()->getLabel())]);
     }
 }
コード例 #5
0
ファイル: ItemListController.php プロジェクト: Tawreh/mtg
 /**
  * Lists the feed items belonging to a feed.
  */
 public function listItems(FeedInterface $feeds_feed, Request $request)
 {
     $processor = $feeds_feed->getType()->getProcessor();
     $header = ['title' => $this->t('Label'), 'imported' => $this->t('Imported'), 'guid' => ['data' => $this->t('GUID'), 'class' => [RESPONSIVE_PRIORITY_LOW]], 'url' => ['data' => $this->t('URL'), 'class' => [RESPONSIVE_PRIORITY_LOW]]];
     $build = [];
     $build['table'] = ['#type' => 'table', '#header' => $header, '#rows' => [], '#empty' => $this->t('There are no items yet.')];
     // @todo Allow processors to create their own entity listings.
     if (!$processor instanceof EntityProcessorInterface) {
         return $build;
     }
     $entity_ids = \Drupal::entityQuery($processor->entityType())->condition('feeds_item.target_id', $feeds_feed->id())->pager(50)->sort('feeds_item.imported', 'DESC')->execute();
     $storage = $this->entityManager()->getStorage($processor->entityType());
     foreach ($storage->loadMultiple($entity_ids) as $entity) {
         $ago = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $entity->get('feeds_item')->imported);
         $row = [];
         // Entity link.
         $row[] = ['data' => $entity->link(Unicode::truncate($entity->label(), 75, TRUE, TRUE)), 'title' => $entity->label()];
         // Imported ago.
         $row[] = $this->t('@time ago', ['@time' => $ago]);
         // Item GUID.
         $row[] = ['data' => SafeMarkup::checkPlain(Unicode::truncate($entity->get('feeds_item')->guid, 30, FALSE, TRUE)), 'title' => $entity->get('feeds_item')->guid];
         // Item URL.
         $row[] = ['data' => SafeMarkup::checkPlain(Unicode::truncate($entity->get('feeds_item')->url, 30, FALSE, TRUE)), 'title' => $entity->get('feeds_item')->url];
         $build['table']['#rows'][] = $row;
     }
     $build['pager'] = ['#type' => 'pager'];
     $build['#title'] = $this->t('%title items', ['%title' => $feeds_feed->label()]);
     return $build;
 }
コード例 #6
0
 /**
  * Removes Simplenews fields.
  */
 public static function removeFields()
 {
     $simplenews_fields_ids = \Drupal::entityQuery('field_config')->condition('field_type', 'simplenews_', 'STARTS_WITH')->execute();
     $simplenews_fields = \Drupal::entityManager()->getStorage('field_config')->loadMultiple($simplenews_fields_ids);
     $field_config_storage = \Drupal::entityManager()->getStorage('field_config');
     $field_config_storage->delete($simplenews_fields);
 }
コード例 #7
0
ファイル: EntityFormDisplay.php プロジェクト: 318io/318-io
 /**
  * Returns the entity_form_display object used to build an entity form.
  *
  * Depending on the configuration of the form mode for the entity bundle, this
  * can be either the display object associated with the form mode, or the
  * 'default' display.
  *
  * This method should only be used internally when rendering an entity form.
  * When assigning suggested display options for a component in a given form
  * mode, entity_get_form_display() should be used instead, in order to avoid
  * inadvertently modifying the output of other form modes that might happen to
  * use the 'default' display too. Those options will then be effectively
  * applied only if the form mode is configured to use them.
  *
  * hook_entity_form_display_alter() is invoked on each display, allowing 3rd
  * party code to alter the display options held in the display before they are
  * used to generate render arrays.
  *
  * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
  *   The entity for which the form is being built.
  * @param string $form_mode
  *   The form mode.
  *
  * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
  *   The display object that should be used to build the entity form.
  *
  * @see entity_get_form_display()
  * @see hook_entity_form_display_alter()
  */
 public static function collectRenderDisplay(FieldableEntityInterface $entity, $form_mode)
 {
     $entity_type = $entity->getEntityTypeId();
     $bundle = $entity->bundle();
     // Check the existence and status of:
     // - the display for the form mode,
     // - the 'default' display.
     if ($form_mode != 'default') {
         $candidate_ids[] = $entity_type . '.' . $bundle . '.' . $form_mode;
     }
     $candidate_ids[] = $entity_type . '.' . $bundle . '.default';
     $results = \Drupal::entityQuery('entity_form_display')->condition('id', $candidate_ids)->condition('status', TRUE)->execute();
     // Load the first valid candidate display, if any.
     $storage = \Drupal::entityManager()->getStorage('entity_form_display');
     foreach ($candidate_ids as $candidate_id) {
         if (isset($results[$candidate_id])) {
             $display = $storage->load($candidate_id);
             break;
         }
     }
     // Else create a fresh runtime object.
     if (empty($display)) {
         $display = $storage->create(array('targetEntityType' => $entity_type, 'bundle' => $bundle, 'mode' => $form_mode, 'status' => TRUE));
     }
     // Let the display know which form mode was originally requested.
     $display->originalMode = $form_mode;
     // Let modules alter the display.
     $display_context = array('entity_type' => $entity_type, 'bundle' => $bundle, 'form_mode' => $form_mode);
     \Drupal::moduleHandler()->alter('entity_form_display', $display, $display_context);
     return $display;
 }
コード例 #8
0
 /**
  * Rolls back the configured migrations.
  */
 public function rollback()
 {
     static::$messages = new DrushLogMigrateMessage();
     $query = \Drupal::entityQuery('migration');
     $names = $query->execute();
     // Order the migrations according to their dependencies.
     /** @var MigrationInterface[] $migrations */
     $migrations = \Drupal::entityManager()->getStorage('migration')->loadMultiple($names);
     // Assume we want all those tagged 'Drupal %'.
     foreach ($migrations as $migration_id => $migration) {
         $keep = FALSE;
         $tags = $migration->get('migration_tags');
         foreach ($tags as $tag) {
             if (strpos($tag, 'Drupal ') === 0) {
                 $keep = TRUE;
                 break;
             }
         }
         if (!$keep) {
             unset($migrations[$migration_id]);
         }
     }
     // Roll back in reverse order.
     $this->migrationList = array_reverse($migrations);
     foreach ($this->migrationList as $migration_id => $migration) {
         drush_print(dt('Rolling back @migration', ['@migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, static::$messages);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'rollback']);
         $migration->delete();
     }
 }
コード例 #9
0
 /**
  * Load an entity by it's label.
  *
  * @param string $label
  *   The label of the entity to load.
  * @param string $entity_type
  *   The entity type to load.
  *
  * @return \Drupal\Core\Entity\EntityInterface
  *   A loaded entity.
  */
 protected function loadEntityByLabel($label, $entity_type = 'node')
 {
     $type_manager = \Drupal::entityTypeManager();
     $label_key = $type_manager->getDefinition($entity_type)->getKey('label');
     $entities = \Drupal::entityQuery($entity_type)->condition($label_key, $label, '=')->execute();
     return $type_manager->getStorage($entity_type)->load(array_shift($entities));
 }
コード例 #10
0
ファイル: AddressFormatTest.php プロジェクト: jokas/d8.dev
 /**
  * Test importing address formats using service.
  */
 function testAddressFormatImport()
 {
     $externalRepository = new AddressFormatRepository();
     $externalCount = count($externalRepository->getAll());
     $count = \Drupal::entityQuery('address_format')->count()->execute();
     $this->assertEqual($externalCount, $count, 'All address formats imported at installation.');
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function content()
 {
     // Get the list of the reservation node ids.
     $storage = \Drupal::entityManager()->getStorage('node');
     $reserved_list = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'balagan_reservation')->condition('field_balagan_reserv_accom', 'NULL', '<>')->condition('field_balagan_reserv_customer', 'NULL', '<>')->execute();
     $reserved_accom = array();
     $build = array();
     foreach ($reserved_list as $nid) {
         $reserved_accom[] = $storage->load($nid)->field_balagan_reserv_accom->getValue()[0]['target_id'];
     }
     if (!empty($reserved_accom)) {
         $accommodations = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'balagan_accommodation')->condition('nid', $reserved_accom, 'NOT IN')->execute();
         foreach ($accommodations as $item) {
             $node = node_load($item);
             $locality = $node->field_balagan_accom_address->getValue()[0]['locality'];
             $start = $node->field_balagan_accom_date->getValue()[0]['value'];
             $end = $node->field_balagan_accom_date->getValue()[1]['value'];
             $people = $node->field_balagan_accom_people->getValue()[0]['value'];
             $link = $node->toLink()->toRenderable();
             $build[] = $link;
             $build[] = array('markup' => array('#type' => 'markup', '#markup' => ' ' . $locality . ' ' . $start . ' - ' . $end . ' ' . 'Room for: ' . $people . '<BR>'));
         }
     }
     return $build;
 }
コード例 #12
0
ファイル: EfqTest.php プロジェクト: ddrozdik/dmaps
 /**
  * Tests that a basic taxonomy entity query works.
  */
 function testTaxonomyEfq()
 {
     $terms = array();
     for ($i = 0; $i < 5; $i++) {
         $term = $this->createTerm($this->vocabulary);
         $terms[$term->id()] = $term;
     }
     $result = \Drupal::entityQuery('taxonomy_term')->execute();
     sort($result);
     $this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
     $tid = reset($result);
     $ids = (object) array('entity_type' => 'taxonomy_term', 'entity_id' => $tid, 'bundle' => $this->vocabulary->id());
     $term = _field_create_entity_from_ids($ids);
     $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
     // Create a second vocabulary and five more terms.
     $vocabulary2 = $this->createVocabulary();
     $terms2 = array();
     for ($i = 0; $i < 5; $i++) {
         $term = $this->createTerm($vocabulary2);
         $terms2[$term->id()] = $term;
     }
     $result = \Drupal::entityQuery('taxonomy_term')->condition('vid', $vocabulary2->id())->execute();
     sort($result);
     $this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', array('%name' => $vocabulary2->label())));
     $tid = reset($result);
     $ids = (object) array('entity_type' => 'taxonomy_term', 'entity_id' => $tid, 'bundle' => $vocabulary2->id());
     $term = _field_create_entity_from_ids($ids);
     $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     /** @var \Drupal\crm_core_contact\Entity\ContactType $entity */
     // First check permission.
     if (parent::checkAccess($entity, $operation, $account)->isForbidden()) {
         return AccessResult::forbidden();
     }
     switch ($operation) {
         case 'enable':
             // Only disabled contact type can be enabled.
             return AccessResult::allowedIf(!$entity->status());
         case 'disable':
             return AccessResult::allowedIf($entity->status());
         case 'delete':
             // If contact instance of this contact type exist, you can't delete it.
             $results = \Drupal::entityQuery('crm_core_contact')->condition('type', $entity->id())->execute();
             return AccessResult::allowedIf(empty($results));
             // @todo Which is it?
         // @todo Which is it?
         case 'edit':
         case 'update':
             // If the contact type is locked, you can't edit it.
             return AccessResult::allowed();
     }
 }
コード例 #14
0
 /**
  * Tests the widget.
  */
 protected function testWidget()
 {
     /** @var \Drupal\currency\ConfigImporterInterface $config_importer */
     $config_importer = \Drupal::service('currency.config_importer');
     $config_importer->importCurrency('EUR');
     $user = $this->drupalCreateUser(['administer user fields']);
     $this->drupalLogin($user);
     // Test the widget when setting a default field value.
     $field_name = strtolower($this->randomMachineName());
     $this->drupalPostForm('admin/config/people/accounts/fields/add-field', ['label' => $this->randomString(), 'field_name' => $field_name, 'new_storage_type' => 'payment_form'], t('Save and continue'));
     $this->drupalPostForm(NULL, [], t('Save field settings'));
     $this->drupalPostForm(NULL, [], t('Add and configure a new line item'));
     $this->drupalPostForm(NULL, ['default_value_input[field_' . $field_name . '][line_items][line_items][payment_basic][plugin_form][description]' => $this->randomString()], t('Save settings'));
     // Get all payment_form fields.
     $field_names = \Drupal::entityQuery('field_storage_config')->condition('type', 'payment_form')->execute();
     $this->assertTrue(in_array('user.field_' . $field_name, $field_names));
     // Test the widget when creating an entity.
     $this->drupalPostForm('user/' . $user->id() . '/edit', ['field_' . $field_name . '[line_items][add_more][type]' => 'payment_basic'], t('Add and configure a new line item'));
     $description = $this->randomString();
     $this->drupalPostForm(NULL, ['field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][amount]' => '9,87', 'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][currency_code]' => 'EUR', 'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][description]' => $description, 'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][quantity]' => 37], t('Save'));
     // Test whether the widget displays field values.
     $this->drupalGet('user/' . $user->id() . '/edit');
     $this->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][amount]', '9.87');
     $this->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][currency_code]', 'EUR');
     $this->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][description]', $description);
     $this->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][quantity]', 37);
 }
コード例 #15
0
 /**
  * Tests that the autocomplete input element appears and the creation of a new
  * entity.
  */
 public function testAutoCreate()
 {
     $this->drupalGet('node/add/' . $this->referencingType);
     $this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.');
     $new_title = $this->randomMachineName();
     // Assert referenced node does not exist.
     $base_query = \Drupal::entityQuery('node');
     $base_query->condition('type', $this->referencedType)->condition('title', $new_title);
     $query = clone $base_query;
     $result = $query->execute();
     $this->assertFalse($result, 'Referenced node does not exist yet.');
     $edit = array('title[0][value]' => $this->randomMachineName(), 'test_field[0][target_id]' => $new_title);
     $this->drupalPostForm("node/add/{$this->referencingType}", $edit, 'Save');
     // Assert referenced node was created.
     $query = clone $base_query;
     $result = $query->execute();
     $this->assertTrue($result, 'Referenced node was created.');
     $referenced_nid = key($result);
     $referenced_node = Node::load($referenced_nid);
     // Assert the referenced node is associated with referencing node.
     $result = \Drupal::entityQuery('node')->condition('type', $this->referencingType)->execute();
     $referencing_nid = key($result);
     $referencing_node = Node::load($referencing_nid);
     $this->assertEqual($referenced_nid, $referencing_node->test_field->target_id, 'Newly created node is referenced from the referencing node.');
     // Now try to view the node and check that the referenced node is shown.
     $this->drupalGet('node/' . $referencing_node->id());
     $this->assertText($referencing_node->label(), 'Referencing node label found.');
     $this->assertText($referenced_node->label(), 'Referenced node label found.');
 }
コード例 #16
0
 /**
  * @{inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $card = $values->_entity;
     $query = \Drupal::entityQuery('card_instance')->condition('field_card_base.entity.id', $card->id())->count();
     $count = $query->execute();
     return $count;
 }
コード例 #17
0
 /**
  * Tests using entity query with ContentEntityNullStorage.
  *
  * @see \Drupal\Core\Entity\Query\Null\Query
  */
 public function testEntityQuery()
 {
     $this->assertIdentical(0, \Drupal::entityQuery('contact_message')->count()->execute(), 'Counting a null storage returns 0.');
     $this->assertIdentical([], \Drupal::entityQuery('contact_message')->execute(), 'Querying a null storage returns an empty array.');
     $this->assertIdentical([], \Drupal::entityQuery('contact_message')->condition('contact_form', 'test')->execute(), 'Querying a null storage returns an empty array and conditions are ignored.');
     $this->assertIdentical([], \Drupal::entityQueryAggregate('contact_message')->aggregate('name', 'AVG')->execute(), 'Aggregate querying a null storage returns an empty array');
 }
コード例 #18
0
 /**
  * Implement getEmails($states, $subscribed, $newsletters)
  */
 function getEmails($states, $subscribed, $newsletters)
 {
     // Build conditions for active state, subscribed state and newsletter selection.
     if (isset($states['active'])) {
         $condition_active[] = SubscriberInterface::ACTIVE;
     }
     if (isset($states['inactive'])) {
         $condition_active[] = SubscriberInterface::INACTIVE;
     }
     if (isset($subscribed['subscribed'])) {
         $condition_subscribed[] = SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED;
     }
     if (isset($subscribed['unsubscribed'])) {
         $condition_subscribed[] = SIMPLENEWS_SUBSCRIPTION_STATUS_UNSUBSCRIBED;
     }
     if (isset($subscribed['unconfirmed'])) {
         $condition_subscribed[] = SIMPLENEWS_SUBSCRIPTION_STATUS_UNCONFIRMED;
     }
     // Get emails from the database.
     $query = \Drupal::entityQuery('simplenews_subscriber')->condition('status', $condition_active)->condition('subscriptions.status', $condition_subscribed)->condition('subscriptions.target_id', (array) $newsletters, 'IN');
     $subscriber_ids = $query->execute();
     $mails = array();
     foreach ($subscriber_ids as $id) {
         $subscriber = simplenews_subscriber_load($id);
         $mails[] = $subscriber->getMail();
     }
     // Return comma separated array of emails or empty text.
     if ($mails) {
         return implode(", ", $mails);
     }
     return t('No addresses were found.');
 }
コード例 #19
0
  /**
   * Search.
   *
   * @return json
   *   Return json.
   */
  public function search($searched, $operation) {
    $idsEntities = \Drupal::entityQuery('ps_product', 'OR')
        ->condition('name', $searched, 'CONTAINS')
        ->condition('detail', $searched, 'CONTAINS')
        ->execute();
    $entities = Product::loadMultiple($idsEntities);
    $i = 0;

    $result = array();
    foreach ($entities as $entity) {
      if ($entity->getType() == $operation) {
        $result[$i] = array(
            'id' => $entity->getId(),
            'name' => $entity->get('name')->value,
            'phone' => $entity->get('phone')->value,
            'cellphone' => $entity->get('cellphone')->value,
            'email' => $entity->get('email')->value,
            'webpage' => $entity->get('webpage')->value,
            'address' => $entity->get('address')->value,
            'detail' => $entity->get('detail')->value,
        );
        $i++;
      }
    }

    $response = new Response();
    $response->setContent(json_encode($result));
    $response->headers->set('Content-Type', 'application/json');
    return $response;
  }
コード例 #20
0
 /**
  * Checks the number of available RDF entities filtered by bundle.
  *
  * @param int $number
  *   The expected number of RDF entities.
  * @param string $type
  *   The RDF type.
  *
  * @throws \Exception
  *   Thrown when the number of RDF entities does not
  *   match the expectation.
  */
 protected function assertRdfEntityCount($number, $type)
 {
     $actual = \Drupal::entityQuery('rdf_entity')->condition('rid', $type)->count()->execute();
     if ($actual != $number) {
         throw new \Exception("Wrong number of {$type} entities. Expected number: {$number}, actual number: {$actual}.");
     }
 }
コード例 #21
0
ファイル: Status.php プロジェクト: pedrocones/hydrotools
 /**
  * {@inheritdoc}
  */
 public function query()
 {
     if (is_array($this->value) && in_array('_active', $this->value)) {
         $active = \Drupal::entityQuery('uc_order_status')->condition('weight', 0, '>=')->execute();
         $this->value = array_merge($this->value, $active);
     }
     parent::query();
 }
コード例 #22
0
ファイル: PretCarburant.php プロジェクト: hacktm15/lapompa
 public static function getPretEntity(Node $benzinarie, Term $tip_carburant)
 {
     $preturi_ids = \Drupal::entityQuery('node')->condition('type', 'pret')->condition('field_benzinarie.target_id', $benzinarie->id())->condition('field_tip_carburant.target_id', $tip_carburant->id())->condition('status', 1)->sort('created', 'DESC')->execute();
     if (count($preturi_ids)) {
         $pret_id = array_shift($preturi_ids);
         return Node::load($pret_id);
     }
 }
コード例 #23
0
ファイル: ExpoCrud.php プロジェクト: 318io/318-io
 private static function _gen_hash($field = '')
 {
     do {
         $hash = DT::random_string(6, true);
         $entity_ids = \Drupal::entityQuery('node')->condition($field . '.value', $hash, '=')->execute();
     } while ($entity_ids);
     return $hash;
 }
コード例 #24
0
 public function __construct(Request $request, $container)
 {
     $type = 'node';
     // Get the entity type from the request.
     $this->query = \Drupal::entityQuery($type);
     $this->storage = $container->get('entity.manager')->getStorage($type);
     $this->container = $container;
     $this->params = $this->getRequestParams($request);
 }
コード例 #25
0
ファイル: EntityReference.php プロジェクト: alnutile/drunatra
 /**
  * {@inheritdoc}
  */
 public function __construct(array $settings, $plugin_id, array $plugin_definition)
 {
     parent::__construct($settings, $plugin_id, $plugin_definition);
     // Calculate the upload directory.
     // $this->availableEntities = \Drupal::service('plugin.manager.entity_reference.selection')
     //   ->getInstance(array('field_definition' => $this->settings['instance']))
     //   ->getReferenceableEntities();
     $this->entityQuery = \Drupal::entityQuery($this->getEntityType());
 }
コード例 #26
0
 /**
  * Deletes Paragraphs datas.
  */
 public static function deleteParagraphs(&$context)
 {
     $paragraph_ids = \Drupal::entityQuery('paragraph')->range(0, 100)->execute();
     $storage = \Drupal::entityTypeManager()->getStorage('paragraph');
     if ($paragraphs = $storage->loadMultiple($paragraph_ids)) {
         $storage->delete($paragraphs);
     }
     $context['finished'] = (int) count($paragraph_ids) < 100;
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     $field = $this->context->getMetadata()->getTypedData()->getParent();
     $uid = $field->getParent()->id();
     $value_taken = (bool) \Drupal::entityQuery('user')->condition('uid', (int) $uid, '<>')->condition($field->getName(), $value)->range(0, 1)->count()->execute();
     if ($value_taken) {
         $this->context->addViolation($constraint->message, array("%value" => $value));
     }
 }
コード例 #28
0
 /**
  * Checks whether a node with the same brafton ID exists in drupal database.
  *
  * @param int $brafton_id The Brafton ID.
  *
  * @return array $nids An array of node ids (nids) that have matching Brafton Id.
  */
 public function brafton_post_exists($brafton_id)
 {
     $loop_section = $this->errors->get_section();
     $this->errors->set_section('Checking for existing Brafton ID ' . $brafton_id);
     $query = \Drupal::entityQuery('node')->condition('field_brafton_id', $brafton_id);
     $nids = $query->execute();
     $this->errors->set_section($loop_section);
     return $nids;
 }
コード例 #29
0
ファイル: WG.php プロジェクト: 318io/318-io
 public static function file_get_id_by_uri($uri)
 {
     $res = \Drupal::entityQuery('file')->condition('uri', $uri)->execute();
     if ($res) {
         $fid = array_shift($res);
         return $fid;
     }
     return false;
 }
コード例 #30
-1
 /**
  * {@inheritdoc}
  */
 public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition)
 {
     $default_value = parent::processDefaultValue($default_value, $entity, $definition);
     if ($default_value) {
         // Convert UUIDs to numeric IDs.
         $uuids = array();
         foreach ($default_value as $delta => $properties) {
             if (isset($properties['target_uuid'])) {
                 $uuids[$delta] = $properties['target_uuid'];
             }
         }
         if ($uuids) {
             $target_type = $definition->getSetting('target_type');
             $entity_ids = \Drupal::entityQuery($target_type)->condition('uuid', $uuids, 'IN')->execute();
             $entities = \Drupal::entityManager()->getStorage($target_type)->loadMultiple($entity_ids);
             $entity_uuids = array();
             foreach ($entities as $id => $entity) {
                 $entity_uuids[$entity->uuid()] = $id;
             }
             foreach ($uuids as $delta => $uuid) {
                 if (isset($entity_uuids[$uuid])) {
                     $default_value[$delta]['target_id'] = $entity_uuids[$uuid];
                     unset($default_value[$delta]['target_uuid']);
                 } else {
                     unset($default_value[$delta]);
                 }
             }
         }
         // Ensure we return consecutive deltas, in case we removed unknown UUIDs.
         $default_value = array_values($default_value);
     }
     return $default_value;
 }