当前位置: 首页>>代码示例>>PHP>>正文


PHP Views::viewsData方法代码示例

本文整理汇总了PHP中Drupal\views\Views::viewsData方法的典型用法代码示例。如果您正苦于以下问题:PHP Views::viewsData方法的具体用法?PHP Views::viewsData怎么用?PHP Views::viewsData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\views\Views的用法示例。


在下文中一共展示了Views::viewsData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 function setUp()
 {
     parent::setUp();
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up term names.
     $this->termNames = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create a vocabulary.
     $this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']);
     $this->vocabulary->save();
     // Add a translatable field to the vocabulary.
     $field = FieldStorageConfig::create(array('field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'type' => 'text'));
     $field->save();
     FieldConfig::create(['field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'label' => 'Foo', 'bundle' => 'views_testing_tags'])->save();
     // Create term with translations.
     $taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']));
     foreach (array('es', 'fr') as $langcode) {
         $translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode]));
         $translation->description->value = $this->termNames[$langcode];
         $translation->field_foo->value = $this->termNames[$langcode];
     }
     $taxonomy->save();
     Views::viewsData()->clear();
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
     $this->container->get('router.builder')->rebuild();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:27,代码来源:TaxonomyFieldFilterTest.php

示例2: buildOptionsForm

 /**
  * Provide a form for setting options.
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     if (isset($this->base_table)) {
         $executable = $form_state->get('view')->getExecutable();
         // A whole bunch of code to figure out what relationships are valid for
         // this item.
         $relationships = $executable->display_handler->getOption('relationships');
         $relationship_options = array();
         foreach ($relationships as $relationship) {
             $relationship_handler = Views::handlerManager('relationship')->getHandler($relationship);
             // If this relationship is valid for this type, add it to the list.
             $data = Views::viewsData()->get($relationship['table']);
             $base = $data[$relationship['field']]['relationship']['base'];
             if ($base == $this->base_table) {
                 $relationship_handler->init($executable, $relationship);
                 $relationship_options[$relationship['id']] = $relationship_handler->adminLabel();
             }
         }
         if (!empty($relationship_options)) {
             $relationship_options = array_merge(array('none' => $this->t('Do not use a relationship')), $relationship_options);
             $rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
             if (empty($relationship_options[$rel])) {
                 // Pick the first relationship.
                 $rel = key($relationship_options);
             }
             $form['relationship'] = array('#type' => 'select', '#title' => $this->t('Relationship'), '#options' => $relationship_options, '#default_value' => $rel);
         } else {
             $form['relationship'] = array('#type' => 'value', '#value' => 'none');
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:35,代码来源:RowPluginBase.php

示例3: setUpFixtures

 /**
  * {@inheritdoc}
  */
 protected function setUpFixtures()
 {
     $this->installEntitySchema('user');
     $this->installConfig(array('user'));
     parent::setUpFixtures();
     // Create a record for uid 1.
     $this->rootUser = User::create(['name' => $this->randomMachineName()]);
     $this->rootUser->save();
     Views::viewsData()->clear();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:RelationshipJoinTestBase.php

示例4: setUpFixtures

 /**
  * Overrides \Drupal\views\Tests\ViewUnitTestBase::setUpFixtures().
  */
 protected function setUpFixtures()
 {
     $this->installEntitySchema('user');
     $this->installConfig(array('user'));
     parent::setUpFixtures();
     // Create a record for uid 1.
     $this->installSchema('system', 'sequences');
     $this->root_user = entity_create('user', array('name' => $this->randomMachineName()));
     $this->root_user->save();
     Views::viewsData()->clear();
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:RelationshipJoinTestBase.php

示例5: getDerivativeDefinitions

 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $views_data = Views::viewsData();
     $base_tables = array_keys($views_data->fetchBaseTables());
     $this->derivatives = array();
     foreach ($base_tables as $table) {
         $views_info = $views_data->get($table);
         if (empty($views_info['table']['wizard_id'])) {
             $this->derivatives[$table] = array('id' => 'standard', 'base_table' => $table, 'title' => $views_info['table']['base']['title'], 'class' => 'Drupal\\views\\Plugin\\views\\wizard\\Standard');
         }
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:DefaultWizardDeriver.php

示例6: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $view = $form_state['view'];
     foreach ($form_state['values'] as $key => $value) {
         // Only save values onto the view if they're actual view properties
         // (as opposed to 'op' or 'form_build_id').
         if (isset($form['details'][$key])) {
             $view->set($key, $value);
         }
     }
     $bases = Views::viewsData()->fetchBaseTables();
     $form_state['#page_title'] = $view->label();
     if (isset($bases[$view->get('base_table')])) {
         $form_state['#page_title'] .= ' (' . $bases[$view->get('base_table')]['title'] . ')';
     }
     $view->cacheSet();
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:20,代码来源:EditDetails.php

示例7: testTaxonomyRelationships

 /**
  * Tests the taxonomy parent plugin UI.
  */
 public function testTaxonomyRelationships()
 {
     // Check the generated views data of taxonomy_index.
     $views_data = Views::viewsData()->get('taxonomy_index');
     // Check the table join data.
     $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
     $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
     $this->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid');
     $this->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid');
     $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
     $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid');
     // Check the generated views data of taxonomy_term_hierarchy.
     $views_data = Views::viewsData()->get('taxonomy_term_hierarchy');
     // Check the table join data.
     $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
     $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent');
     $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
     $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
     // Check the parent relationship data.
     $this->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data');
     $this->assertEqual($views_data['parent']['relationship']['field'], 'parent');
     $this->assertEqual($views_data['parent']['relationship']['label'], t('Parent'));
     $this->assertEqual($views_data['parent']['relationship']['id'], 'standard');
     // Check the parent filter and argument data.
     $this->assertEqual($views_data['parent']['filter']['id'], 'numeric');
     $this->assertEqual($views_data['parent']['argument']['id'], 'taxonomy');
     // Check an actual test view.
     $view = Views::getView('test_taxonomy_term_relationship');
     $this->executeView($view);
     /** @var \Drupal\views\ResultRow $row */
     foreach ($view->result as $index => $row) {
         // Check that the actual ID of the entity is the expected one.
         $this->assertEqual($row->tid, $this->terms[$index]->id());
         // Also check that we have the correct result entity.
         $this->assertEqual($row->_entity->id(), $this->terms[$index]->id());
         $this->assertTrue($row->_entity instanceof TermInterface);
         if (!$index) {
             $this->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface);
             $this->assertEqual($row->_relationship_entities['parent']->id(), $this->term2->id());
             $this->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2->id());
         }
         $this->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface);
         $this->assertEqual($row->_relationship_entities['nid']->id(), $this->nodes[$index]->id());
     }
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:48,代码来源:TaxonomyRelationshipTest.php

示例8: testRelationshipViewsData

 /**
  * Tests views data generated for image field relationship.
  *
  * @see image_field_views_data()
  * @see image_field_views_data_views_data_alter()
  */
 public function testRelationshipViewsData()
 {
     // Create image field to entity_test.
     FieldStorageConfig::create(array('entity_type' => 'entity_test', 'field_name' => 'field_base_image', 'type' => 'image'))->save();
     FieldConfig::create(array('entity_type' => 'entity_test', 'field_name' => 'field_base_image', 'bundle' => 'entity_test'))->save();
     // Check the generated views data.
     $views_data = Views::viewsData()->get('entity_test__field_base_image');
     $relationship = $views_data['field_base_image_target_id']['relationship'];
     $this->assertEqual($relationship['id'], 'standard');
     $this->assertEqual($relationship['base'], 'file_managed');
     $this->assertEqual($relationship['base field'], 'fid');
     $this->assertEqual($relationship['entity type'], 'file');
     // Check the backwards reference.
     $views_data = Views::viewsData()->get('file_managed');
     $relationship = $views_data['reverse_field_base_image_entity_test']['relationship'];
     $this->assertEqual($relationship['id'], 'entity_reverse');
     $this->assertEqual($relationship['base'], 'entity_test');
     $this->assertEqual($relationship['base field'], 'id');
     $this->assertEqual($relationship['field table'], 'entity_test__field_base_image');
     $this->assertEqual($relationship['field field'], 'field_base_image_target_id');
     $this->assertEqual($relationship['field_name'], 'field_base_image');
     $this->assertEqual($relationship['entity_type'], 'entity_test');
     $this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
     // Create image field to entity_test_mul.
     FieldStorageConfig::create(array('entity_type' => 'entity_test_mul', 'field_name' => 'field_data_image', 'type' => 'image'))->save();
     FieldConfig::create(array('entity_type' => 'entity_test_mul', 'field_name' => 'field_data_image', 'bundle' => 'entity_test_mul'))->save();
     // Check the generated views data.
     $views_data = Views::viewsData()->get('entity_test_mul__field_data_image');
     $relationship = $views_data['field_data_image_target_id']['relationship'];
     $this->assertEqual($relationship['id'], 'standard');
     $this->assertEqual($relationship['base'], 'file_managed');
     $this->assertEqual($relationship['base field'], 'fid');
     $this->assertEqual($relationship['entity type'], 'file');
     // Check the backwards reference.
     $views_data = Views::viewsData()->get('file_managed');
     $relationship = $views_data['reverse_field_data_image_entity_test_mul']['relationship'];
     $this->assertEqual($relationship['id'], 'entity_reverse');
     $this->assertEqual($relationship['base'], 'entity_test_mul_property_data');
     $this->assertEqual($relationship['base field'], 'id');
     $this->assertEqual($relationship['field table'], 'entity_test_mul__field_data_image');
     $this->assertEqual($relationship['field field'], 'field_data_image_target_id');
     $this->assertEqual($relationship['field_name'], 'field_data_image');
     $this->assertEqual($relationship['entity_type'], 'entity_test_mul');
     $this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:51,代码来源:ImageViewsDataTest.php

示例9: getTableEntityType

 protected function getTableEntityType($table)
 {
     static $recursion = 0;
     if ($table = Views::viewsData()->get($table)) {
         if (!empty($table['table']['entity type'])) {
             // Reset recursion when we found a value.
             $recursion = 0;
             return $table['table']['entity type'];
         } elseif (!empty($table['table']['join']) && count($table['table']['join']) == 1) {
             if (empty($recursion)) {
                 $join_table = array_pop(array_keys($table['table']['join']));
                 $recursion++;
                 return $this->getTableEntityType($join_table);
             }
         }
     }
     return NULL;
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:18,代码来源:CalendarViewsTrait.php

示例10: testRelationship

 /**
  * Tests using the views relationship.
  */
 public function testRelationship()
 {
     // Check just the generated views data.
     $views_data_field_test = Views::viewsData()->get('entity_test__field_test');
     $this->assertEqual($views_data_field_test['field_test']['relationship']['id'], 'standard');
     $this->assertEqual($views_data_field_test['field_test']['relationship']['base'], 'entity_test');
     $this->assertEqual($views_data_field_test['field_test']['relationship']['base field'], 'id');
     $this->assertEqual($views_data_field_test['field_test']['relationship']['relationship field'], 'field_test_target_id');
     // Check the backwards reference.
     $views_data_entity_test = Views::viewsData()->get('entity_test');
     $this->assertEqual($views_data_entity_test['reverse__entity_test__field_test']['relationship']['id'], 'entity_reverse');
     $this->assertEqual($views_data_entity_test['reverse__entity_test__field_test']['relationship']['base'], 'entity_test');
     $this->assertEqual($views_data_entity_test['reverse__entity_test__field_test']['relationship']['base field'], 'id');
     $this->assertEqual($views_data_entity_test['reverse__entity_test__field_test']['relationship']['field table'], 'entity_test__field_test');
     $this->assertEqual($views_data_entity_test['reverse__entity_test__field_test']['relationship']['field field'], 'field_test_target_id');
     // Check an actual test view.
     $view = Views::getView('test_entity_reference_view');
     $this->executeView($view);
     foreach (array_keys($view->result) as $index) {
         // Check that the actual ID of the entity is the expected one.
         $this->assertEqual($view->result[$index]->id, $this->entities[$index + 1]->id());
         // Also check that we have the correct result entity.
         $this->assertEqual($view->result[$index]->_entity->id(), $this->entities[$index + 1]->id());
         // Test the forward relationship.
         // The second and third entity refer to the first one.
         // The value key on the result will be in the format
         // BASE_TABLE_FIELD_NAME.
         $this->assertEqual($view->result[$index]->entity_test_entity_test__field_test_id, $index == 0 ? NULL : 1);
         if ($index > 0) {
             // Test that the correct relationship entity is on the row.
             $this->assertEqual($view->result[$index]->_relationship_entities['test_relationship']->id(), 1);
         }
     }
     $view->destroy();
     $this->executeView($view, 'embed_1');
     foreach (array_keys($view->result) as $index) {
         $this->assertEqual($view->result[$index]->id, $this->entities[$index + 1]->id());
         $this->assertEqual($view->result[$index]->_entity->id(), $this->entities[$index + 1]->id());
         // The second and third entity refer to the first one.
         $this->assertEqual($view->result[$index]->entity_test_entity_test__field_test_id, $index == 0 ? NULL : 1);
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:45,代码来源:EntityReferenceRelationshipTest.php

示例11: testProfileRelationship

 /**
  * Tests views relationship with multiple referenced entities.
  *
  * Relationship is required, so only users with profiles will be listed.
  */
 public function testProfileRelationship()
 {
     $profile_type = $this->createProfileType();
     $user[0] = $user1 = $this->createUser();
     $user2 = $this->createUser();
     $user[1] = $user3 = $this->createUser();
     $user4 = $this->createUser();
     $profile[0] = $this->createProfile($profile_type, $user1);
     $profile[1] = $this->createProfile($profile_type, $user3);
     Views::viewsData()->clear();
     // Check table relationship exists.
     $views_data = Views::viewsData()->get('users_field_data');
     $this->assertEqual($views_data['profile']['relationship']['base'], 'profile');
     $this->assertEqual($views_data['profile']['relationship']['base field'], 'uid');
     $view = Views::getView('users');
     $this->executeView($view);
     // Ensure values are populated for user and profiles.
     foreach ($view->result as $index => $row) {
         $this->assertEqual($row->uid, $user[$index]->id(), 'User ' . $user[$index]->id() . ' found on row: ' . $index);
         $this->assertEqual($row->profile_users_field_data_profile_id, $profile[$index]->id(), 'Profile ' . $profile[$index]->id() . ' found on view: ' . $index);
     }
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:27,代码来源:ProfileViewTest.php

示例12: query

 /**
  * Called to implement a relationship in a query.
  */
 public function query()
 {
     $this->ensureMyTable();
     // First, relate our base table to the current base table to the
     // field, using the base table's id field to the field's column.
     $views_data = Views::viewsData()->get($this->table);
     $left_field = $views_data['table']['base']['field'];
     $first = array('left_table' => $this->tableAlias, 'left_field' => $left_field, 'table' => $this->definition['field table'], 'field' => $this->definition['field field'], 'adjusted' => TRUE);
     if (!empty($this->options['required'])) {
         $first['type'] = 'INNER';
     }
     if (!empty($this->definition['join_extra'])) {
         $first['extra'] = $this->definition['join_extra'];
     }
     if (!empty($def['join_id'])) {
         $id = $def['join_id'];
     } else {
         $id = 'standard';
     }
     $first_join = $this->joinManager->createInstance($id, $first);
     $this->first_alias = $this->query->addTable($this->definition['field table'], $this->relationship, $first_join);
     // Second, relate the field table to the entity specified using
     // the entity id on the field table and the entity's id field.
     $second = array('left_table' => $this->first_alias, 'left_field' => 'entity_id', 'table' => $this->definition['base'], 'field' => $this->definition['base field'], 'adjusted' => TRUE);
     if (!empty($this->options['required'])) {
         $second['type'] = 'INNER';
     }
     if (!empty($def['join_id'])) {
         $id = $def['join_id'];
     } else {
         $id = 'standard';
     }
     $second_join = $this->joinManager->createInstance($id, $second);
     $second_join->adjusted = TRUE;
     // use a short alias for this:
     $alias = $this->definition['field_name'] . '_' . $this->table;
     $this->alias = $this->query->addRelationship($alias, $second_join, $this->definition['base'], $this->relationship);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:41,代码来源:EntityReverse.php

示例13: execute

  /**
   * Executes the query and fills the associated view object with according
   * values.
   *
   * Values to set: $view->result, $view->total_rows, $view->execute_time,
   * $view->current_page.
   */
  public function execute(ViewExecutable $view) {
    $query = $view->build_info['query'];
    $count_query = $view->build_info['count_query'];

    $query->addMetaData('view', $view);
    $count_query->addMetaData('view', $view);

    if (empty($this->options['disable_sql_rewrite'])) {
      $base_table_data = Views::viewsData()->get($this->view->storage->get('base_table'));
      if (isset($base_table_data['table']['base']['access query tag'])) {
        $access_tag = $base_table_data['table']['base']['access query tag'];
        $query->addTag($access_tag);
        $count_query->addTag($access_tag);
      }

      if (isset($base_table_data['table']['base']['query metadata'])) {
        foreach ($base_table_data['table']['base']['query metadata'] as $key => $value) {
          $query->addMetaData($key, $value);
          $count_query->addMetaData($key, $value);
        }
      }
    }

    if ($query) {
      $additional_arguments = \Drupal::moduleHandler()->invokeAll('views_query_substitutions', array($view));

      // Count queries must be run through the preExecute() method.
      // If not, then hook_query_node_access_alter() may munge the count by
      // adding a distinct against an empty query string
      // (e.g. COUNT DISTINCT(1) ...) and no pager will return.
      // See pager.inc > PagerDefault::execute()
      // http://api.drupal.org/api/drupal/includes--pager.inc/function/PagerDefault::execute/7
      // See https://www.drupal.org/node/1046170.
      $count_query->preExecute();

      // Build the count query.
      $count_query = $count_query->countQuery();

      // Add additional arguments as a fake condition.
      // XXX: this doesn't work, because PDO mandates that all bound arguments
      // are used on the query. TODO: Find a better way to do this.
      if (!empty($additional_arguments)) {
        // $query->where('1 = 1', $additional_arguments);
        // $count_query->where('1 = 1', $additional_arguments);
      }

      $start = microtime(TRUE);

      try {
        if ($view->pager->useCountQuery() || !empty($view->get_total_rows)) {
          $view->pager->executeCountQuery($count_query);
        }

        // Let the pager modify the query to add limits.
        $view->pager->preExecute($query);

        if (!empty($this->limit) || !empty($this->offset)) {
          // We can't have an offset without a limit, so provide a very large limit instead.
          $limit  = intval(!empty($this->limit) ? $this->limit : 999999);
          $offset = intval(!empty($this->offset) ? $this->offset : 0);
          $query->range($offset, $limit);
        }

        $result = $query->execute();
        $result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow');

        // Setup the result row objects.
        $view->result = iterator_to_array($result);
        array_walk($view->result, function(ResultRow $row, $index) {
          $row->index = $index;
        });

        $view->pager->postExecute($view->result);
        $view->pager->updatePageInfo();
        $view->total_rows = $view->pager->getTotalItems();

        // Load all entities contained in the results.
        $this->loadEntities($view->result);
      }
      catch (DatabaseExceptionWrapper $e) {
        $view->result = array();
        if (!empty($view->live_preview)) {
          drupal_set_message($e->getMessage(), 'error');
        }
        else {
          throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[{$view->storage->id()}]: {$e->getMessage()}");
        }
      }

    }
    else {
      $start = microtime(TRUE);
    }
//.........这里部分代码省略.........
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:101,代码来源:Sql.php

示例14: testDataTableRelationshipWithLongFieldName

 /**
  * Tests views data generated for relationship.
  *
  * @see entity_reference_field_views_data()
  */
 public function testDataTableRelationshipWithLongFieldName()
 {
     // Create some test entities which link each other.
     $referenced_entity = EntityTest::create();
     $referenced_entity->save();
     $entity = EntityTestMulChanged::create();
     $entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
     $entity->save();
     $this->entities[] = $entity;
     $entity = EntityTestMulChanged::create();
     $entity->field_test_data_with_a_long_name->target_id = $referenced_entity->id();
     $entity->save();
     $this->entities[] = $entity;
     Views::viewsData()->clear();
     // Check an actual test view.
     $view = Views::getView('test_entity_reference_entity_test_view_long');
     $this->executeView($view);
     /** @var \Drupal\views\ResultRow $row */
     foreach ($view->result as $index => $row) {
         // Check that the actual ID of the entity is the expected one.
         $this->assertEqual($row->id, $this->entities[$index]->id());
         // Also check that we have the correct result entity.
         $this->assertEqual($row->_entity->id(), $this->entities[$index]->id());
         // Test the forward relationship.
         //$this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
         // Test that the correct relationship entity is on the row.
         $this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->id(), 1);
         $this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->bundle(), 'entity_test');
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:35,代码来源:EntityReferenceRelationshipTest.php

示例15: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('user');
     $this->installEntitySchema('entity_test_rev');
     // Bypass any field access.
     $this->adminUser = User::create(['name' => $this->randomString()]);
     $this->adminUser->save();
     $this->container->get('current_user')->setAccount($this->adminUser);
     $this->testUsers = [];
     for ($i = 0; $i < 5; $i++) {
         $this->testUsers[$i] = User::create(['name' => 'test ' . $i, 'timezone' => User::getAllowedTimezones()[$i]]);
         $this->testUsers[$i]->save();
     }
     // Setup a field storage and field, but also change the views data for the
     // entity_test entity type.
     $field_storage = FieldStorageConfig::create(['field_name' => 'field_test', 'type' => 'integer', 'entity_type' => 'entity_test']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'field_test', 'entity_type' => 'entity_test', 'bundle' => 'entity_test']);
     $field->save();
     $field_storage_multiple = FieldStorageConfig::create(['field_name' => 'field_test_multiple', 'type' => 'integer', 'entity_type' => 'entity_test', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED]);
     $field_storage_multiple->save();
     $field_multiple = FieldConfig::create(['field_name' => 'field_test_multiple', 'entity_type' => 'entity_test', 'bundle' => 'entity_test']);
     $field_multiple->save();
     $random_number = (string) 30856;
     $random_number_multiple = (string) 1370359990;
     for ($i = 0; $i < 5; $i++) {
         $this->entities[$i] = $entity = EntityTest::create(['bundle' => 'entity_test', 'name' => 'test ' . $i, 'field_test' => $random_number[$i], 'field_test_multiple' => [$random_number_multiple[$i * 2], $random_number_multiple[$i * 2 + 1]], 'user_id' => $this->testUsers[$i]->id()]);
         $entity->save();
     }
     // Setup some test data for entities with revisions.
     // We are testing both base field revisions and field config revisions.
     $field_storage = FieldStorageConfig::create(['field_name' => 'field_test', 'type' => 'integer', 'entity_type' => 'entity_test_rev']);
     $field_storage->save();
     $field = FieldConfig::create(['field_name' => 'field_test', 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev']);
     $field->save();
     $field_storage_multiple = FieldStorageConfig::create(['field_name' => 'field_test_multiple', 'type' => 'integer', 'entity_type' => 'entity_test_rev', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED]);
     $field_storage_multiple->save();
     $field_multiple = FieldConfig::create(['field_name' => 'field_test_multiple', 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev']);
     $field_multiple->save();
     $this->entityRevision = [];
     $this->entityRevision[0] = $entity = EntityTestRev::create(['name' => 'base value', 'field_test' => 1, 'field_test_multiple' => [1, 3, 7], 'user_id' => $this->testUsers[0]->id()]);
     $entity->save();
     $original_entity = clone $entity;
     $entity = clone $original_entity;
     $entity->setNewRevision(TRUE);
     $entity->name->value = 'revision value1';
     $entity->field_test->value = 2;
     $entity->field_test_multiple[0]->value = 0;
     $entity->field_test_multiple[1]->value = 3;
     $entity->field_test_multiple[2]->value = 5;
     $entity->user_id->target_id = $this->testUsers[1]->id();
     $entity->save();
     $this->entityRevision[1] = $entity;
     $entity = clone $original_entity;
     $entity->setNewRevision(TRUE);
     $entity->name->value = 'revision value2';
     $entity->field_test->value = 3;
     $entity->field_test_multiple[0]->value = 9;
     $entity->field_test_multiple[1]->value = 9;
     $entity->field_test_multiple[2]->value = 9;
     $entity->user_id->target_id = $this->testUsers[2]->id();
     $entity->save();
     $this->entityRevision[2] = $entity;
     $this->entityRevision[3] = $entity = EntityTestRev::create(['name' => 'next entity value', 'field_test' => 4, 'field_test_multiple' => [2, 9, 9], 'user_id' => $this->testUsers[3]->id()]);
     $entity->save();
     \Drupal::state()->set('entity_test.views_data', ['entity_test' => ['id' => ['field' => ['id' => 'field']]], 'entity_test_rev_revision' => ['id' => ['field' => ['id' => 'field']]]]);
     Views::viewsData()->clear();
 }
开发者ID:scratch,项目名称:gai,代码行数:73,代码来源:FieldFieldTest.php


注:本文中的Drupal\views\Views::viewsData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。