Exemplo n.º 1
0
 /**
  * Create a vocabulary and some taxonomy terms, ensuring they're loaded
  * correctly using entity_load_multiple().
  */
 function testTaxonomyTermMultipleLoad()
 {
     // Create a vocabulary.
     $vocabulary = $this->createVocabulary();
     // Create five terms in the vocabulary.
     $i = 0;
     while ($i < 5) {
         $i++;
         $this->createTerm($vocabulary);
     }
     // Load the terms from the vocabulary.
     $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
     $count = count($terms);
     $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
     // Load the same terms again by tid.
     $terms2 = entity_load_multiple('taxonomy_term', array_keys($terms));
     $this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.');
     $this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.');
     // Remove one term from the array, then delete it.
     $deleted = array_shift($terms2);
     $deleted->delete();
     $deleted_term = entity_load('taxonomy_term', $deleted->id());
     $this->assertFalse($deleted_term);
     // Load terms from the vocabulary by vid.
     $terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
     $this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.');
     $this->assertFalse(isset($terms3[$deleted->id()]));
     // Create a single term and load it by name.
     $term = $this->createTerm($vocabulary);
     $loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->getName()));
     $this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
     $loaded_term = reset($loaded_terms);
     $this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.');
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $settings = $editor->getSettings();
     $medium_editors = array();
     foreach (entity_load_multiple('medium_editor') as $medium_editor) {
         $medium_editors[$medium_editor->id()] = $medium_editor->label();
     }
     // Default editor
     $form['default_editor'] = array('#type' => 'select', '#title' => $this->t('Medium Editor'), '#options' => $medium_editors, '#default_value' => $settings['default_editor'], '#description' => $this->t('Select the default editor for the authorized roles. Editors can be configured at <a href="!url">Medium admin page</a>.', array('!url' => \Drupal::url('medium.admin'))), '#empty_option' => '- ' . $this->t('Select an editor') . ' -');
     // Roles editors
     $role_ids = array();
     if ($format_form = $form_state->getCompleteForm()) {
         if (isset($format_form['roles']['#value'])) {
             $role_ids = $format_form['roles']['#value'];
         } elseif (isset($format_form['roles']['#default_value'])) {
             $role_ids = $format_form['roles']['#default_value'];
         }
     } elseif ($format = $editor->getFilterFormat()) {
         $role_ids = array_keys(filter_get_roles_by_format($format));
     }
     if (count($role_ids) > 1) {
         $form['roles_editors'] = array('#type' => 'details', '#title' => t('Role specific editors'));
         $roles = user_roles();
         foreach ($role_ids as $role_id) {
             $form['roles_editors'][$role_id] = array('#type' => 'select', '#title' => $this->t('Editor for %role', array('%role' => $roles[$role_id]->label())), '#options' => $medium_editors, '#default_value' => isset($settings['roles_editors'][$role_id]) ? $settings['roles_editors'][$role_id] : '', '#empty_option' => '- ' . $this->t('Use the default') . ' -');
         }
     }
     return $form;
 }
Exemplo n.º 3
0
 public function preRender(&$values)
 {
     $vocabularies = entity_load_multiple('taxonomy_vocabulary');
     $this->field_alias = $this->aliases['nid'];
     $nids = array();
     foreach ($values as $result) {
         if (!empty($result->{$this->aliases['nid']})) {
             $nids[] = $result->{$this->aliases['nid']};
         }
     }
     if ($nids) {
         $vocabs = array_filter($this->options['vids']);
         if (empty($this->options['limit'])) {
             $vocabs = array();
         }
         $result = \Drupal::entityManager()->getStorage('taxonomy_term')->getNodeTerms($nids, $vocabs);
         foreach ($result as $node_nid => $data) {
             foreach ($data as $tid => $term) {
                 $this->items[$node_nid][$tid]['name'] = \Drupal::entityManager()->getTranslationFromContext($term)->label();
                 $this->items[$node_nid][$tid]['tid'] = $tid;
                 $this->items[$node_nid][$tid]['vocabulary_vid'] = $term->getVocabularyId();
                 $this->items[$node_nid][$tid]['vocabulary'] = String::checkPlain($vocabularies[$term->getVocabularyId()]->label());
                 if (!empty($this->options['link_to_taxonomy'])) {
                     $this->items[$node_nid][$tid]['make_link'] = TRUE;
                     $this->items[$node_nid][$tid]['path'] = 'taxonomy/term/' . $tid;
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test', 'type' => 'text'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_two', 'type' => 'integer', 'cardinality' => -1))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_two', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_three', 'type' => 'decimal'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_three', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_integer_selectlist', 'type' => 'integer'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_integer_selectlist', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_exclude_unset', 'type' => 'text'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_exclude_unset', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_multivalue', 'type' => 'decimal', 'precision' => '10', 'scale' => '2', 'cardinality' => -1))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_multivalue', 'bundle' => 'test_planet'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical1', 'type' => 'integer'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical1', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical2', 'type' => 'integer'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical2', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_link', 'type' => 'link'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_link', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_filefield', 'type' => 'file'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_filefield', 'bundle' => 'story'))->save();
     // Add some id mappings for the dependant migrations.
     $id_mappings = array('d6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_node' => array(array(array(1), array(1)), array(array(2), array(2)), array(array(3), array(3))));
     $this->prepareMigrations($id_mappings);
     $migrations = entity_load_multiple('migration', array('d6_cck_field_values:*'));
     foreach ($migrations as $migration) {
         $executable = new MigrateExecutable($migration, $this);
         $executable->import();
     }
 }
 /**
  * {@inheritdoc}
  *
  * Mark the accessible IDs a user can see. We do not unset unaccessible
  * values, as other may want to act on those values, even if they can
  * not be accessed.
  */
 public function prepareView(array $entities_items)
 {
     $target_ids = array();
     // Collect every possible entity attached to any of the entities.
     foreach ($entities_items as $items) {
         foreach ($items as $item) {
             if (!empty($item->target_id)) {
                 $target_ids[] = $item->target_id;
             }
         }
     }
     $target_type = $this->getFieldSetting('target_type');
     $target_entities = array();
     if ($target_ids) {
         $target_entities = entity_load_multiple($target_type, $target_ids);
     }
     // Iterate through the fieldable entities again to attach the loaded data.
     foreach ($entities_items as $items) {
         $rekey = FALSE;
         foreach ($items as $item) {
             if ($item->target_id !== 0 && !isset($target_entities[$item->target_id])) {
                 // The entity no longer exists, so empty the item.
                 $item->setValue(NULL);
                 $rekey = TRUE;
                 continue;
             }
             $item->originalEntity = $target_entities[$item->target_id];
         }
         // Re-key the items array if needed.
         if ($rekey) {
             $items->filterEmptyItems();
         }
     }
 }
 public function testTagsField()
 {
     $this->drupalLogin($this->admin_user);
     $this->drupalGet('node/add/page');
     $title_key = 'title[0][value]';
     $body_key = 'body[0][value]';
     // Fill in node creation form and preview node.
     $edit = array();
     $edit[$title_key] = $this->randomMachineName(8);
     $edit[$body_key] = $this->randomMachineName(16);
     $edit['tags'] = 'tag1, tag2, tag3';
     $this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
     $tags = entity_load_multiple('taxonomy_term');
     foreach ($tags as $tag) {
         $this->assertSitemapLinkValues('taxonomy_term', $tag->id(), array('status' => 0, 'priority' => 0.5, 'changefreq' => 0));
         $tag->delete();
     }
     xmlsitemap_link_bundle_settings_save('taxonomy_term', 'tags', array('status' => 1, 'priority' => 0.2, 'changefreq' => XMLSITEMAP_FREQUENCY_HOURLY));
     $this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
     $tags = entity_load_multiple('taxonomy_term');
     foreach ($tags as $tag) {
         $this->assertSitemapLinkValues('taxonomy_term', $tag->id(), array('status' => 1, 'priority' => 0.2, 'changefreq' => XMLSITEMAP_FREQUENCY_HOURLY));
         $tag->delete();
     }
 }
 protected function setUp()
 {
     parent::setUp();
     // Create a new content type
     $content_type = $this->drupalCreateContentType();
     // Add a node of the new content type.
     $node_data = array('type' => $content_type->type);
     $this->container->get('comment.manager')->addDefaultField('node', $content_type->type);
     $this->node = $this->drupalCreateNode($node_data);
     // Force a flush of the in-memory storage.
     $this->container->get('views.views_data')->clear();
     // Create some comments and attach them to the created node.
     for ($i = 0; $i < $this->masterDisplayResults; $i++) {
         /** @var \Drupal\comment\CommentInterface $comment */
         $comment = entity_create('comment', array('status' => CommentInterface::PUBLISHED, 'field_name' => 'comment', 'entity_type' => 'node', 'entity_id' => $this->node->id()));
         $comment->setOwnerId(0);
         $comment->setSubject('Test comment ' . $i);
         $comment->comment_body->value = 'Test body ' . $i;
         $comment->comment_body->format = 'full_html';
         // Ensure comments are sorted in ascending order.
         $time = REQUEST_TIME + ($this->masterDisplayResults - $i);
         $comment->setCreatedTime($time);
         $comment->changed->value = $time;
         $comment->save();
     }
     // Store all the nodes just created to access their properties on the tests.
     $this->commentsCreated = entity_load_multiple('comment');
     // Sort created comments in descending order.
     ksort($this->commentsCreated, SORT_NUMERIC);
 }
 /**
  * Set up an administrative user account and testing keys.
  */
 public function setUp()
 {
     // Call parent::setUp() allowing test cases to pass further modules.
     parent::setUp();
     $this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration', 'administer xmlsitemap', 'access content'));
     $this->drupalLogin($this->admin_user);
     if (!$this->languageManager->getLanguage('fr')) {
         // Add a new language.
         $language = new Language(array('id' => 'fr', 'name' => 'French'));
         language_save($language);
     }
     if (!$this->languageManager->getLanguage('en')) {
         // Add a new language.
         $language = new Language(array('id' => 'en', 'name' => 'English'));
         language_save($language);
     }
     // Create the two different language-context sitemaps.
     $previous_sitemaps = entity_load_multiple('xmlsitemap');
     foreach ($previous_sitemaps as $previous_sitemap) {
         $previous_sitemap->delete();
     }
     $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
     $sitemap->context = array('language' => 'en');
     xmlsitemap_sitemap_save($sitemap);
     $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
     $sitemap->context = array('language' => 'fr');
     xmlsitemap_sitemap_save($sitemap);
 }
Exemplo n.º 9
0
 /**
  * Test the breakpoints defined by the custom group.
  */
 public function testThemeBreakpointGroup()
 {
     // Verify the breakpoint group 'test' was created by breakpoint_test_theme.
     $breakpoint_group_obj = entity_create('breakpoint_group', array('label' => 'Test Theme', 'name' => 'test', 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, 'source' => 'breakpoint_test_theme', 'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.test'));
     $breakpoint_group_obj->addBreakpoints(entity_load_multiple('breakpoint', array('theme.breakpoint_test_theme.mobile', 'theme.breakpoint_test_theme.narrow', 'theme.breakpoint_test_theme.wide')));
     // Verify we can load this breakpoint defined by the theme.
     $this->verifyBreakpointGroup($breakpoint_group_obj);
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     foreach (entity_load_multiple('taxonomy_vocabulary') as $voc) {
         $this->derivatives[$voc->vid] = $base_plugin_definition;
         $this->derivatives[$voc->vid]['admin_label'] = t('Tags in @voc', array('@voc' => $voc->name));
     }
     return $this->derivatives;
 }
 /**
  * {@inheritdoc}
  *
  * Mark the accessible IDs a user can see. We do not unset unaccessible
  * values, as other may want to act on those values, even if they can
  * not be accessed.
  */
 public function prepareView(array $entities_items)
 {
     $target_ids = array();
     $revision_ids = array();
     // Collect every possible entity attached to any of the entities.
     foreach ($entities_items as $items) {
         foreach ($items as $item) {
             if (!empty($item->revision_id)) {
                 $revision_ids[] = $item->revision_id;
             } elseif (!empty($item->target_id)) {
                 $target_ids[] = $item->target_id;
             }
         }
     }
     $target_type = $this->getFieldSetting('target_type');
     $target_entities = array();
     if ($target_ids) {
         $target_entities = entity_load_multiple($target_type, $target_ids);
     }
     if ($revision_ids) {
         // We need to load the revisions one by-one.
         foreach ($revision_ids as $revision_id) {
             $target_entity = entity_revision_load($target_type, $revision_id);
             // Use the revision ID in the key.
             $identifier = $target_entity->id() . ':' . $revision_id;
             $target_entities[$identifier] = $target_entity;
         }
     }
     // Iterate through the fieldable entities again to attach the loaded data.
     foreach ($entities_items as $items) {
         $rekey = FALSE;
         foreach ($items as $item) {
             // If we have a revision ID, the key uses it as well.
             $identifier = !empty($item->revision_id) ? $item->target_id . ':' . $item->revision_id : $item->target_id;
             if ($item->target_id !== 0) {
                 if (!isset($target_entities[$identifier])) {
                     // The entity no longer exists, so empty the item.
                     $item->setValue(NULL);
                     $rekey = TRUE;
                     continue;
                 }
                 $item->entity = $target_entities[$identifier];
                 if (!$item->entity->access('view')) {
                     continue;
                 }
             } else {
                 // This is an "auto_create" item, just leave the entity in place.
             }
             // Mark item as accessible.
             $item->access = TRUE;
         }
         // Rekey the items array if needed.
         if ($rekey) {
             $items->filterEmptyItems();
         }
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $block_contents = entity_load_multiple('block_content');
     foreach ($block_contents as $block_content) {
         $this->derivatives[$block_content->uuid()] = $base_plugin_definition;
         $this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label();
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migrations = entity_load_multiple('migration', array('d6_term_node:*'));
     foreach ($migrations as $migration) {
         $executable = new MigrateExecutable($migration, $this);
         $executable->import();
     }
 }
Exemplo n.º 14
0
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     $vocabularies = entity_load_multiple('taxonomy_vocabulary');
     $options = array();
     foreach ($vocabularies as $voc) {
         $options[$voc->id()] = $voc->label();
     }
     $form['vids'] = array('#type' => 'checkboxes', '#title' => $this->t('Vocabularies'), '#options' => $options, '#default_value' => $this->options['vids'], '#description' => $this->t('Choose which vocabularies you wish to relate. Remember that every term found will create a new record, so this relationship is best used on just one vocabulary that has only one term per node.'));
     parent::buildOptionsForm($form, $form_state);
 }
Exemplo n.º 15
0
 public function preRender($result)
 {
     $cids = array();
     foreach ($result as $row) {
         $cids[] = $row->cid;
     }
     $this->comments = entity_load_multiple('comment', $cids);
     foreach ($this->comments as $comment) {
         $comment->depth = count(explode('.', $comment->getThread())) - 1;
     }
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $block_contents = entity_load_multiple('block_content');
     /** @var $block_content \Drupal\block_content\Entity\BlockContent */
     foreach ($block_contents as $block_content) {
         $this->derivatives[$block_content->uuid()] = $base_plugin_definition;
         $this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label();
         $this->derivatives[$block_content->uuid()]['config_dependencies']['content'] = array($block_content->getConfigDependencyName());
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $id_mappings = array('d6_term_node' => array(array(array(2), array(1))), 'd6_node_revision' => array(array(array(2), array(2))));
     $this->prepareMigrations($id_mappings);
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migrations = entity_load_multiple('migration', array('d6_term_node_revision:*'));
     foreach ($migrations as $migration) {
         $executable = new MigrateExecutable($migration, $this);
         $executable->import();
     }
 }
Exemplo n.º 18
0
 /**
  * Test the complete Drupal migration.
  */
 public function testDrupal()
 {
     $dumps = $this->getDumps();
     $this->loadDumps($dumps);
     $classes = $this->getTestClassesList();
     $extension_install_storage = new ExtensionInstallStorage(\Drupal::service('config.storage'), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE);
     foreach ($classes as $class) {
         if (is_subclass_of($class, '\\Drupal\\migrate\\Tests\\MigrateDumpAlterInterface')) {
             $class::migrateDumpAlter($this);
         }
     }
     // Run every migration in the order specified by the storage controller.
     foreach (entity_load_multiple('migration', static::$migrations) as $migration) {
         (new MigrateExecutable($migration, $this))->import();
         // Ensure that the default migration has the correct dependencies.
         list($base_name, ) = explode(':', $migration->id(), 2);
         $default_configuration = $extension_install_storage->read('migrate.migration.' . $base_name);
         $default_dependencies = isset($default_configuration['dependencies']) ? $default_configuration['dependencies'] : [];
         $this->assertEqual($default_dependencies, $migration->getDependencies(), SafeMarkup::format('Dependencies in @id match after installing. Default configuration @first is equal to active configuration @second.', array('@id' => $migration->id(), '@first' => var_export($default_dependencies, TRUE), '@second' => var_export($migration->getDependencies(), TRUE))));
     }
     foreach ($classes as $class) {
         $test_object = new $class($this->testId);
         $test_object->databasePrefix = $this->databasePrefix;
         $test_object->container = $this->container;
         // run() does a lot of setup and tear down work which we don't need:
         // it would setup a new database connection and wouldn't find the
         // Drupal dump. Also by skipping the setUp() methods there are no id
         // mappings or entities prepared. The tests run against solely migrated
         // data.
         foreach (get_class_methods($test_object) as $method) {
             if (strtolower(substr($method, 0, 4)) == 'test') {
                 // Insert a fail record. This will be deleted on completion to ensure
                 // that testing completed.
                 $method_info = new \ReflectionMethod($class, $method);
                 $caller = array('file' => $method_info->getFileName(), 'line' => $method_info->getStartLine(), 'function' => $class . '->' . $method . '()');
                 $completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller);
                 // Run the test method.
                 try {
                     $test_object->{$method}();
                 } catch (\Exception $e) {
                     $this->exceptionHandler($e);
                 }
                 // Remove the completion check record.
                 TestBase::deleteAssert($completion_check_id);
             }
         }
         // Add the pass/fail/exception/debug results.
         foreach ($this->results as $key => &$value) {
             $value += $test_object->results[$key];
         }
     }
 }
Exemplo n.º 19
0
 public function buildOptionsForm(&$form, &$form_state)
 {
     $form['term_page'] = array('#type' => 'checkbox', '#title' => t('Load default filter from term page'), '#default_value' => $this->options['term_page']);
     $form['node'] = array('#type' => 'checkbox', '#title' => t('Load default filter from node page, that\'s good for related taxonomy blocks'), '#default_value' => $this->options['node']);
     $form['limit'] = array('#type' => 'checkbox', '#title' => t('Limit terms by vocabulary'), '#default_value' => $this->options['limit'], '#states' => array('visible' => array(':input[name="options[argument_default][taxonomy_tid][node]"]' => array('checked' => TRUE))));
     $options = array();
     $vocabularies = entity_load_multiple('taxonomy_vocabulary');
     foreach ($vocabularies as $voc) {
         $options[$voc->id()] = $voc->label();
     }
     $form['vids'] = array('#type' => 'checkboxes', '#title' => t('Vocabularies'), '#options' => $options, '#default_value' => $this->options['vids'], '#states' => array('visible' => array(':input[name="options[argument_default][taxonomy_tid][limit]"]' => array('checked' => TRUE), ':input[name="options[argument_default][taxonomy_tid][node]"]' => array('checked' => TRUE))));
     $form['anyall'] = array('#type' => 'radios', '#title' => t('Multiple-value handling'), '#default_value' => $this->options['anyall'], '#options' => array(',' => t('Filter to items that share all terms'), '+' => t('Filter to items that share any term')), '#states' => array('visible' => array(':input[name="options[argument_default][taxonomy_tid][node]"]' => array('checked' => TRUE))));
 }
 /**
  * Tests a simple site export import case.
  */
 public function testExportImport()
 {
     $this->originalSlogan = \Drupal::config('system.site')->get('slogan');
     $this->newSlogan = $this->randomString(16);
     $this->assertNotEqual($this->newSlogan, $this->originalSlogan);
     \Drupal::config('system.site')->set('slogan', $this->newSlogan)->save();
     $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan);
     // Create a content type.
     $this->content_type = $this->drupalCreateContentType();
     // Create a field.
     $this->fieldName = drupal_strtolower($this->randomMachineName());
     $this->fieldStorage = entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text'));
     $this->fieldStorage->save();
     entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->content_type->type))->save();
     entity_get_form_display('node', $this->content_type->type, 'default')->setComponent($this->fieldName, array('type' => 'text_textfield'))->save();
     entity_get_display('node', $this->content_type->type, 'full')->setComponent($this->fieldName)->save();
     $this->drupalGet('node/add/' . $this->content_type->type);
     $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
     // Export the configuration.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
     $this->tarball = $this->drupalGetContent();
     \Drupal::config('system.site')->set('slogan', $this->originalSlogan)->save();
     $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->originalSlogan);
     // Delete the custom field.
     $fields = entity_load_multiple('field_config');
     foreach ($fields as $field) {
         if ($field->field_name == $this->fieldName) {
             $field->delete();
         }
     }
     $field_storages = entity_load_multiple('field_storage_config');
     foreach ($field_storages as $field_storage) {
         if ($field_storage->field_name == $this->fieldName) {
             $field_storage->delete();
         }
     }
     $this->drupalGet('node/add/' . $this->content_type->type);
     $this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed');
     // Import the configuration.
     $filename = 'temporary://' . $this->randomMachineName();
     file_put_contents($filename, $this->tarball);
     $this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
     $this->drupalPostForm(NULL, array(), 'Import all');
     $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan);
     $this->drupalGet('node/add');
     $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
     \Drupal::config('system.site')->set('slogan', $this->originalSlogan)->save();
     $this->drupalGet('admin/config/development/configuration');
     $this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site');
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function generateElements(array $values)
 {
     if ($values['kill']) {
         foreach ($values['vids'] as $vid) {
             $this->deleteVocabularyTerms($vid);
         }
         $this->setMessage($this->t('Deleted existing terms.'));
     }
     $vocabs = entity_load_multiple('taxonomy_vocabulary', $values['vids']);
     $new_terms = $this->generateTerms($values['num'], $vocabs, $values['title_length']);
     if (!empty($new_terms)) {
         $this->setMessage($this->t('Created the following new terms: !terms', array('!terms' => implode(', ', $new_terms))));
     }
 }
 /**
  * Tests that the order is correct when loading several migrations.
  */
 public function testMigrateDependenciesOrder()
 {
     $migration_items = array('d6_comment', 'd6_filter_format', 'd6_node');
     $migrations = entity_load_multiple('migration', $migration_items);
     $expected_order = array('d6_filter_format', 'd6_node', 'd6_comment');
     $this->assertEqual(array_keys($migrations), $expected_order);
     $expected_requirements = array('d6_node', 'd6_node_type', 'd6_filter_format', 'd6_user', 'd6_comment_entity_display', 'd6_comment_entity_form_display');
     // Migration dependencies for comment include dependencies for node
     // migration as well.
     $actual_requirements = $migrations['d6_comment']->get('requirements');
     $this->assertEqual(count($actual_requirements), count($expected_requirements));
     foreach ($expected_requirements as $requirement) {
         $this->assertEqual($actual_requirements[$requirement], $requirement);
     }
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test', 'type' => 'text'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_two', 'type' => 'integer', 'cardinality' => -1))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_two', 'bundle' => 'story'))->save();
     // Add some id mappings for the dependant migrations.
     $id_mappings = array('d6_cck_field_values' => array(array(array(1), array(1))), 'd6_node' => array(array(array(1), array(1)), array(array(2), array(2))), 'd6_node_revision' => array(array(array(1), array(1))));
     $this->prepareMigrations($id_mappings);
     $migrations = entity_load_multiple('migration', array('d6_cck_field_revision:*'));
     foreach ($migrations as $migration) {
         $executable = new MigrateExecutable($migration, $this);
         $executable->import();
     }
 }
 /**
  * Test the complete Drupal migration.
  */
 public function testDrupal()
 {
     $dumps = $this->getDumps();
     $this->loadDumps($dumps);
     $classes = $this->getTestClassesList();
     foreach ($classes as $class) {
         if (is_subclass_of($class, '\\Drupal\\migrate\\Tests\\MigrateDumpAlterInterface')) {
             $class::migrateDumpAlter($this);
         }
     }
     // Run every migration in the order specified by the storage controller.
     foreach (entity_load_multiple('migration', static::$migrations) as $migration) {
         (new MigrateExecutable($migration, $this))->import();
     }
     foreach ($classes as $class) {
         $test_object = new $class($this->testId);
         $test_object->databasePrefix = $this->databasePrefix;
         $test_object->container = $this->container;
         // run() does a lot of setup and tear down work which we don't need:
         // it would setup a new database connection and wouldn't find the
         // Drupal dump. Also by skipping the setUp() methods there are no id
         // mappings or entities prepared. The tests run against solely migrated
         // data.
         foreach (get_class_methods($test_object) as $method) {
             if (strtolower(substr($method, 0, 4)) == 'test') {
                 // Insert a fail record. This will be deleted on completion to ensure
                 // that testing completed.
                 $method_info = new \ReflectionMethod($class, $method);
                 $caller = array('file' => $method_info->getFileName(), 'line' => $method_info->getStartLine(), 'function' => $class . '->' . $method . '()');
                 $completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller);
                 // Run the test method.
                 try {
                     $test_object->{$method}();
                 } catch (\Exception $e) {
                     $this->exceptionHandler($e);
                 }
                 // Remove the completion check record.
                 TestBase::deleteAssert($completion_check_id);
             }
         }
         // Add the pass/fail/exception/debug results.
         foreach ($this->results as $key => &$value) {
             $value += $test_object->results[$key];
         }
     }
 }
 /**
  * Gets the entity labels.
  */
 protected function getLabels(FieldItemListInterface $items, $delta)
 {
     if ($items->isEmpty()) {
         return array();
     }
     $entity_labels = array();
     // Load those entities and loop through them to extract their labels.
     $entities = entity_load_multiple($this->getFieldSetting('target_type'), $this->getEntityIds($items, $delta));
     foreach ($entities as $entity_id => $entity_item) {
         $label = $entity_item->label();
         $key = "{$label} ({$entity_id})";
         // Labels containing commas or quotes must be wrapped in quotes.
         $key = Tags::encode($key);
         $entity_labels[] = $key;
     }
     return $entity_labels;
 }
Exemplo n.º 26
0
 /**
  * Tests that CSRF check is triggered for Cookie Auth requests.
  */
 public function testCookieAuth()
 {
     $this->drupalLogin($this->account);
     $curl_options = $this->getCurlOptions();
     // Try to create an entity without the CSRF token.
     $this->curlExec($curl_options);
     $this->assertResponse(403);
     // Ensure that the entity was not created.
     $this->assertFalse(entity_load_multiple($this->testEntityType, NULL, TRUE), 'No entity has been created in the database.');
     // Create an entity with the CSRF token.
     $token = $this->drupalGet('rest/session/token');
     $curl_options[CURLOPT_HTTPHEADER][] = "X-CSRF-Token: {$token}";
     $this->curlExec($curl_options);
     $this->assertResponse(201);
     // Ensure that the entity was created.
     $loaded_entity = $this->loadEntityFromLocationHeader($this->drupalGetHeader('location'));
     $this->assertTrue($loaded_entity, 'An entity was created in the database');
 }
 /**
  * Tests the Drupal 6 user pictures to Drupal 8 migration.
  */
 public function testUserPictures()
 {
     $file_ids = array();
     foreach (entity_load('migration', 'd6_user_picture_file')->getIdMap() as $destination_ids) {
         $file_ids[] = reset($destination_ids);
     }
     $files = entity_load_multiple('file', $file_ids);
     /** @var \Drupal\file\FileInterface $file */
     $file = array_shift($files);
     $this->assertEqual($file->getFilename(), 'image-test.jpg');
     $this->assertEqual($file->getFileUri(), 'public://image-test.jpg');
     $this->assertEqual($file->getSize(), 1901);
     $this->assertEqual($file->getMimeType(), 'image/jpeg');
     $file = array_shift($files);
     $this->assertEqual($file->getFilename(), 'image-test.png');
     $this->assertEqual($file->getFileUri(), 'public://image-test.png');
     $this->assertFalse($files);
 }
Exemplo n.º 28
0
 public function tagcloudsPageChunk($tagclouds_vocs = '')
 {
     $vocs = tagclouds_vocs_load($tagclouds_vocs);
     if (empty($vocs)) {
         foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) {
             $vocs[] = $vocabulary->vid;
         }
     }
     $config = \Drupal::config('tagclouds.admin_page');
     $tags = tagclouds_get_tags($vocs, $config->get('tagclouds_levels'), $config->get('tagclouds_page_amount'));
     $tags = tagclouds_sort_tags($tags);
     $output = _theme('tagclouds_weighted', array('terms' => $tags));
     if (!$output) {
         throw new NotFoundHttpException();
     }
     $output = "<div class=\"wrapper tagclouds\">{$output}</div>";
     return $output;
 }
Exemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, array &$form_state)
 {
     $responsive_image_options = array();
     $responsive_image_mappings = entity_load_multiple('responsive_image_mapping');
     if ($responsive_image_mappings && !empty($responsive_image_mappings)) {
         foreach ($responsive_image_mappings as $machine_name => $responsive_image_mapping) {
             if ($responsive_image_mapping->hasMappings()) {
                 $responsive_image_options[$machine_name] = $responsive_image_mapping->label();
             }
         }
     }
     $elements['responsive_image_mapping'] = array('#title' => t('Responsive image mapping'), '#type' => 'select', '#default_value' => $this->getSetting('responsive_image_mapping'), '#required' => TRUE, '#options' => $responsive_image_options);
     $image_styles = image_style_options(FALSE);
     $elements['fallback_image_style'] = array('#title' => t('Fallback image style'), '#type' => 'select', '#default_value' => $this->getSetting('fallback_image_style'), '#empty_option' => t('Automatic'), '#options' => $image_styles);
     $link_types = array('content' => t('Content'), 'file' => t('File'));
     $elements['image_link'] = array('#title' => t('Link image to'), '#type' => 'select', '#default_value' => $this->getSetting('image_link'), '#empty_option' => t('Nothing'), '#options' => $link_types);
     return $elements;
 }
Exemplo n.º 30
0
 /**
  * Drush execution method. Runs imports on the supplied manifest.
  */
 public function import()
 {
     /** @var \Drupal\migrate\MigrateTemplateStorage $template_storage */
     $template_storage = \Drupal::service('migrate.template_storage');
     $this->setupLegacyDb();
     $migration_ids = [];
     $migrations = [];
     foreach ($this->migrationList as $migration_info) {
         if (is_array($migration_info)) {
             // The migration is stored as the key in the info array.
             $migration_id = key($migration_info);
         } else {
             // If it wasn't an array then the info is just the migration_id.
             $migration_id = $migration_info;
         }
         $migration_ids[] = $migration_id;
         $template = $template_storage->getTemplateByName($migration_id) ?: [];
         if (is_array($migration_info)) {
             // If there is some existing global overrides then we merge them in.
             if (isset($GLOBALS['config'][$migration_id])) {
                 $migration_info = NestedArray::mergeDeep($GLOBALS['config'][$migration_id], $migration_info);
             }
             $migration_info = NestedArray::mergeDeep($template, $migration_info);
         } else {
             $migration_info = $template;
         }
         if ($migration_info && !Migration::load($migration_id)) {
             $migration = Migration::create($migration_info);
             $migration->save();
         }
     }
     // Load all the migrations at once so they're correctly ordered.
     foreach (entity_load_multiple('migration', $migration_ids) as $migration) {
         $executable = $this->executeMigration($migration);
         // Store all the migrations for later.
         $migrations[$migration->id()] = array('executable' => $executable, 'migration' => $migration, 'source' => $migration->get('source'), 'destination' => $migration->get('destination'));
     }
     // Warn the user if any migrations were not found.
     $nonexistent_migrations = array_diff($migration_ids, array_keys($migrations));
     if (count($nonexistent_migrations) > 0) {
         drush_log(dt('The following migrations were not found: !migrations', array('!migrations' => implode(', ', $nonexistent_migrations))), 'warning');
     }
     return $migrations;
 }