/** * Tests boolean field. */ function testBooleanField() { $on = $this->randomMachineName(); $off = $this->randomMachineName(); $label = $this->randomMachineName(); // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomMachineName()); $this->field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'boolean', 'settings' => array('on_label' => $on, 'off_label' => $off))); $this->field_storage->save(); $this->field = FieldConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE)); $this->field->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox'))->save(); // Create a display for the full view mode. entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'boolean'))->save(); // Display creation form. $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.'); $this->assertRaw($on); // Submit and ensure it is accepted. $edit = array("{$field_name}[value]" => 1); $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\\d+)|', $this->url, $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); // Verify that boolean value is displayed. $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $content = $display->build($entity); $this->drupalSetContent(drupal_render($content)); $this->assertRaw('<div class="field-item">' . $on . '</div>'); // Test the display_label option. entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox', 'settings' => array('display_label' => TRUE)))->save(); $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.'); $this->assertNoRaw($on); $this->assertText($this->field->label()); // Go to the form display page and check if the default settings works as // expected. $fieldEditUrl = 'entity_test/structure/entity_test/form-display'; $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); $this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox available.')); // Enable setting. $edit = array('fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1); $this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update"); $this->drupalPostForm(NULL, NULL, 'Save'); // Go again to the form display page and check if the setting // is stored and has the expected effect. $this->drupalGet($fieldEditUrl); $this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.'); $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); $this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox is available')); $this->assertFieldByXPath('*//input[@id="edit-fields-' . $field_name . '-settings-edit-form-settings-display-label" and @value="1"]', TRUE, t('Display label changes label of the checkbox')); // Test the boolean field settings. $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage'); $this->assertFieldById('edit-field-storage-settings-on-label', $on); $this->assertFieldById('edit-field-storage-settings-off-label', $off); }
/** * Tests email field. */ function testEmailField() { // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); $this->fieldStorage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email')); $this->fieldStorage->save(); $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test']); $this->field->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'email_default', 'settings' => array('placeholder' => '*****@*****.**')))->save(); // Create a display for the full view mode. entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'email_mailto'))->save(); // Display creation form. $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget found.'); $this->assertRaw('placeholder="*****@*****.**"'); // Submit a valid email address and ensure it is accepted. $value = '*****@*****.**'; $edit = array("{$field_name}[0][value]" => $value); $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\\d+)|', $this->url, $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->assertRaw($value); // Verify that a mailto link is displayed. $entity = EntityTest::load($id); $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $content = $display->build($entity); $this->setRawContent(\Drupal::service('renderer')->renderRoot($content)); $this->assertLinkByHref('mailto:test@example.com'); }
/** * XXXXX. * @param \Drupal\field\Entity\FieldStorageConfig $field_storage. * @return array * xxx */ protected function buildRow(FieldStorageConfig $field_storage) { $row = []; if ($field_storage->isLocked()) { $row[0]['class'] = array('menu-disabled'); $row[0]['data']['id'] = $this->t('@field_name (Locked)', array('@field_name' => $field_storage->getName())); } else { $row[0]['data'] = $field_storage->getName(); } $row[1]['data'] = $field_storage->getType(); $row[2]['data'] = $field_storage->getTargetEntityTypeId(); $row[3]['data'] = implode(",", $field_storage->getBundles()); $default_type = $this->fieldPermissions->fieldGetPermissionType($field_storage); if ($default_type == FIELD_PERMISSIONS_PUBLIC) { $row[4]['data'] = t("Public field (author and administrators can edit, everyone can view)"); $row[4]['colspan'] = 5; } elseif ($default_type == FIELD_PERMISSIONS_PRIVATE) { $row[4]['data'] = t("Private field (only author and administrators can edit and view)"); $row[4]['colspan'] = 5; } elseif ($default_type == FIELD_PERMISSIONS_CUSTOM) { $row[4]['data'] = t("Custom field Permission ()"); $row[4]['colspan'] = 5; } return $row; }
/** * Tests the views data generation. */ public function testViewsData() { // Test that the field is not exposed to views, since contact_message // entities have no storage. $table_name = 'contact_message__' . $this->fieldStorage->getName(); $data = $this->container->get('views.views_data')->get($table_name); $this->assertFalse($data, 'The field is not exposed to Views.'); }
protected function setUp() { parent::setUp(); $this->field_storage = entity_create('field_storage_config', array('name' => strtolower($this->randomMachineName()), 'entity_type' => 'contact_message', 'type' => 'text')); $this->field_storage->save(); entity_create('contact_category', array('id' => 'contact_message', 'label' => 'Test contact category'))->save(); entity_create('field_instance_config', array('field_storage' => $this->field_storage, 'bundle' => 'contact_message'))->save(); $this->container->get('views.views_data')->clear(); }
/** * Alters the field configuration for fields related to rdf entities. * * @param \Drupal\field\Entity\FieldStorageConfig $storage * The field configuration storage entity. * @param array &$values * An associative array of field values. This array include any additional * data a field formatter includes. * * @ingroup rdf_entity_api */ function hook_rdf_apply_default_fields_alter(\Drupal\field\Entity\FieldStorageConfig $storage, &$values) { if ($storage->getType() == 'text_long') { // Handle multiple values in a field. foreach ($values as &$value) { $value['format'] == 'my_custom_persistent_filter'; } } }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->installSchema('system', array('router')); $this->fieldStorageDefinition = array('name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array('allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'))); $this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition); $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test')); $this->instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_buttons'))->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->container->get('router.builder')->rebuild(); $this->fieldStorageDefinition = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array('allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'))); $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition); $this->fieldStorage->save(); $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test']); $this->field->save(); entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_buttons'))->save(); }
/** * Tests URI field. */ public function testUriField() { $label = $this->randomMachineName(); // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'uri']); $this->fieldStorage->save(); $this->field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE, 'settings' => ['size' => 123, 'placeholder' => '']]); $this->field->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, ['type' => 'uri'])->save(); }
/** * Creates a date test field. */ protected function createField() { $field_name = Unicode::strtolower($this->randomMachineName()); $type = $this->getTestFieldType(); $widget_type = $formatter_type = $type . '_default'; $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => $type, 'settings' => ['datetime_type' => DateRangeItem::DATETIME_TYPE_DATE]]); $this->fieldStorage->save(); $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE]); $this->field->save(); EntityFormDisplay::load('entity_test.entity_test.default')->setComponent($field_name, ['type' => $widget_type])->save(); $this->displayOptions = ['type' => $formatter_type, 'label' => 'hidden', 'settings' => ['format_type' => 'medium'] + $this->defaultSettings]; EntityViewDisplay::create(['targetEntityType' => $this->field->getTargetEntityTypeId(), 'bundle' => $this->field->getTargetBundle(), 'mode' => 'full', 'status' => TRUE])->setComponent($field_name, $this->displayOptions)->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create content type with unlimited text field. $this->nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); // Create the unlimited text field. $this->fieldName = 'field_views_testing_group_rows'; $this->fieldStorage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED]); $this->fieldStorage->save(); // Create an instance of the text field on the content type. $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => $this->nodeType->id()]); $this->field->save(); $edit = ['title' => $this->randomMachineName(), $this->fieldName => ['a', 'b', 'c']]; $this->drupalCreateNode($edit); }
/** * Creates the test image field. */ protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_image'; $this->cardinality = 3; FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'image', 'cardinality' => $this->cardinality))->save(); FieldConfig::create(['entity_type' => $this->entityTypeId, 'field_name' => $this->fieldName, 'bundle' => $this->entityTypeId, 'label' => 'Test translatable image field', 'third_party_settings' => array('content_translation' => array('translation_sync' => array('file' => FALSE, 'alt' => 'alt', 'title' => 'title')))])->save(); }
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(); }
protected function setUp() { parent::setUp(); // Create a 'test_field' field and storage for validation. FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field'))->save(); FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'entity_test'])->save(); }
protected function setUp() { parent::setUp(); $this->addDefaultCommentField('node', 'page'); $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content')); $this->drupalLogin($web_user); // Add a vocabulary so we can test different view modes. $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '')); $vocabulary->save(); $this->vocabulary = $vocabulary; // Add a term to the vocabulary. $term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $term->save(); $this->term = $term; // Create an image field. FieldStorageConfig::create(['field_name' => 'field_image', 'entity_type' => 'node', 'type' => 'image', 'settings' => [], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED])->save(); $field_config = FieldConfig::create(['field_name' => 'field_image', 'label' => 'Images', 'entity_type' => 'node', 'bundle' => 'page', 'required' => FALSE, 'settings' => []]); $field_config->save(); // Create a field. $this->fieldName = Unicode::strtolower($this->randomMachineName()); $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE); $this->createEntityReferenceField('node', 'page', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); entity_get_form_display('node', 'page', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_autocomplete_tags'))->save(); // Show on default display and teaser. entity_get_display('node', 'page', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save(); entity_get_display('node', 'page', 'teaser')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save(); entity_get_form_display('node', 'page', 'default')->setComponent('field_image', array('type' => 'image_image', 'settings' => []))->save(); entity_get_display('node', 'page', 'default')->setComponent('field_image')->save(); }
/** * Tests entity form language. */ function testEntityFormLanguage() { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'administer content types')); $this->drupalLogin($web_user); // Create a node with language LanguageInterface::LANGCODE_NOT_SPECIFIED. $edit = array(); $edit['title[0][value]'] = $this->randomMachineName(8); $edit['body[0][value]'] = $this->randomMachineName(16); $this->drupalGet('node/add/page'); $form_langcode = \Drupal::state()->get('entity_test.form_langcode'); $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $this->assertTrue($node->language()->getId() == $form_langcode, 'Form language is the same as the entity language.'); // Edit the node and test the form language. $this->drupalGet($this->langcodes[0] . '/node/' . $node->id() . '/edit'); $form_langcode = \Drupal::state()->get('entity_test.form_langcode'); $this->assertTrue($node->language()->getId() == $form_langcode, 'Form language is the same as the entity language.'); // Explicitly set form langcode. $langcode = $this->langcodes[0]; $form_state_additions['langcode'] = $langcode; \Drupal::service('entity.form_builder')->getForm($node, 'default', $form_state_additions); $form_langcode = \Drupal::state()->get('entity_test.form_langcode'); $this->assertTrue($langcode == $form_langcode, 'Form language is the same as the language parameter.'); // Enable language selector. $this->drupalGet('admin/structure/types/manage/page'); $edit = array('language_configuration[language_alterable]' => TRUE, 'language_configuration[langcode]' => LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); // Create a node with language. $edit = array(); $langcode = $this->langcodes[0]; $edit['title[0][value]'] = $this->randomMachineName(8); $edit['body[0][value]'] = $this->randomMachineName(16); $edit['langcode[0][value]'] = $langcode; $this->drupalPostForm('node/add/page', $edit, t('Save')); $this->assertText(t('Basic page @title has been created.', array('@title' => $edit['title[0][value]'])), 'Basic page created.'); // Verify that the creation message contains a link to a node. $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/')); $this->assert(isset($view_link), 'The message area contains a link to a node'); // Check to make sure the node was created. $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $this->assertTrue($node, 'Node found in database.'); // Make body translatable. $field_storage = FieldStorageConfig::loadByName('node', 'body'); $field_storage->setTranslatable(TRUE); $field_storage->save(); $field_storage = FieldStorageConfig::loadByName('node', 'body'); $this->assertTrue($field_storage->isTranslatable(), 'Field body is translatable.'); // Create a body translation and check the form language. $langcode2 = $this->langcodes[1]; $translation = $node->addTranslation($langcode2); $translation->title->value = $this->randomString(); $translation->body->value = $this->randomMachineName(16); $translation->setOwnerId($web_user->id()); $node->save(); $this->drupalGet($langcode2 . '/node/' . $node->id() . '/edit'); $form_langcode = \Drupal::state()->get('entity_test.form_langcode'); $this->assertTrue($langcode2 == $form_langcode, "Node edit form language is {$langcode2}."); }
/** * Tests migration of user profile fields. */ public function testUserProfileFields() { // Migrated a text field. $field_storage = FieldStorageConfig::load('user.profile_color'); $this->assertIdentical('text', $field_storage->getType(), 'Field type is text.'); $this->assertIdentical(1, $field_storage->getCardinality(), 'Text field has correct cardinality'); // Migrated a textarea. $field_storage = FieldStorageConfig::load('user.profile_biography'); $this->assertIdentical('text_long', $field_storage->getType(), 'Field type is text_long.'); // Migrated checkbox field. $field_storage = FieldStorageConfig::load('user.profile_sell_address'); $this->assertIdentical('boolean', $field_storage->getType(), 'Field type is boolean.'); // Migrated selection field. $field_storage = FieldStorageConfig::load('user.profile_sold_to'); $this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.'); $settings = $field_storage->getSettings(); $this->assertEqual($settings['allowed_values'], array('Pill spammers' => 'Pill spammers', 'Fitness spammers' => 'Fitness spammers', 'Back\\slash' => 'Back\\slash', 'Forward/slash' => 'Forward/slash', 'Dot.in.the.middle' => 'Dot.in.the.middle', 'Faithful servant' => 'Faithful servant', 'Anonymous donor' => 'Anonymous donor')); $this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.'); // Migrated list field. $field_storage = FieldStorageConfig::load('user.profile_bands'); $this->assertIdentical('text', $field_storage->getType(), 'Field type is text.'); $this->assertIdentical(-1, $field_storage->getCardinality(), 'List field has correct cardinality'); /* // Migrated URL field. $field_storage = FieldStorageConfig::load('user.profile_blog'); $this->assertIdentical('link', $field_storage->getType(), 'Field type is link.'); */ // Migrated date field. $field_storage = FieldStorageConfig::load('user.profile_birthdate'); $this->assertIdentical('datetime', $field_storage->getType(), 'Field type is datetime.'); $this->assertIdentical('date', $field_storage->getSettings()['datetime_type']); }
protected function setUp() { parent::setUp(); // Let there be T-rex. \Drupal::state()->set('editor_test_give_me_a_trex_thanks', TRUE); \Drupal::service('plugin.manager.editor')->clearCachedDefinitions(); // Add text formats. $filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array())); $filtered_html_format->save(); $full_html_format = entity_create('filter_format', array('format' => 'full_html', 'name' => 'Full HTML', 'weight' => 1, 'filters' => array())); $full_html_format->save(); // Create article node type. $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); // Create page node type, but remove the body. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page')); $body = FieldConfig::loadByName('node', 'page', 'body'); $body->delete(); // Create a formatted text field, which uses an <input type="text">. FieldStorageConfig::create(array('field_name' => 'field_text', 'entity_type' => 'node', 'type' => 'text'))->save(); FieldConfig::create(array('field_name' => 'field_text', 'entity_type' => 'node', 'label' => 'Textfield', 'bundle' => 'page'))->save(); entity_get_form_display('node', 'page', 'default')->setComponent('field_text')->save(); // Create 3 users, each with access to different text formats. $this->untrustedUser = $this->drupalCreateUser(array('create article content', 'edit any article content')); $this->normalUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html')); $this->privilegedUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'create page content', 'edit any page content', 'use text format filtered_html', 'use text format full_html')); }
/** * Displays links to all products that have not been categorized. * * @return * Renderable form array. */ public function orphans() { $build = array(); if ($this->config('taxonomy.settings')->get('maintain_index_table')) { $vid = $this->config('uc_catalog.settings')->get('vocabulary'); $product_types = uc_product_types(); $field = FieldStorageConfig::loadByName('node', 'taxonomy_catalog'); //@todo - figure this out // $field is a config object, not an array, so this doesn't work. //$types = array_intersect($product_types, $field['bundles']['node']); $types = $product_types; //temporary to get this to work at all $result = db_query('SELECT DISTINCT n.nid, n.title FROM {node_field_data} n LEFT JOIN (SELECT ti.nid, td.vid FROM {taxonomy_index} ti LEFT JOIN {taxonomy_term_data} td ON ti.tid = td.tid WHERE td.vid = :vid) txnome ON n.nid = txnome.nid WHERE n.type IN (:types[]) AND txnome.vid IS NULL', [':vid' => $vid, ':types[]' => $types]); $rows = array(); while ($node = $result->fetchObject()) { $rows[] = $this->l($node->title, Url::fromRoute('entity.node.edit_form', ['node' => $node->nid], ['query' => ['destination' => 'admin/store/products/orphans']])); } if (count($rows) > 0) { $build['orphans'] = array('#theme' => 'item_list', '#items' => $rows); } else { $build['orphans'] = array('#markup' => $this->t('All products are currently listed in the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>'); } } else { $build['orphans'] = array('#markup' => $this->t('The node terms index is not being maintained, so Ubercart can not determine which products are not entered into the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>'); } return $build; }
/** * Re-save all field storage config objects to add 'custom_storage' property. */ function field_post_update_save_custom_storage_property() { foreach (FieldStorageConfig::loadMultiple() as $field_storage_config) { $field_storage_config->save(); } return t('All field storage configuration objects re-saved.'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create Page content type. if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); } // Add two new languages. ConfigurableLanguage::createFromLangcode('fr')->save(); ConfigurableLanguage::createFromLangcode('es')->save(); // Make the body field translatable. The title is already translatable by // definition. $field_storage = FieldStorageConfig::loadByName('node', 'body'); $field_storage->translatable = TRUE; $field_storage->save(); // Set up node titles. They should not include the words "French", // "English", or "Spanish", as there is a language field in the view // that prints out those words. $this->node_titles = array('es' => array('Primero nodo es', 'Segundo nodo es', 'Tercera nodo es'), 'en' => array('First node en', 'Second node en'), 'fr' => array('Premier nœud fr')); // Create nodes with translations. foreach ($this->node_titles['es'] as $index => $title) { $node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'es', 'type' => 'page', 'promote' => 1)); foreach (array('en', 'fr') as $langcode) { if (isset($this->node_titles[$langcode][$index])) { $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index])); $translation->body->value = $this->randomMachineName(32); } } $node->save(); } $user = $this->drupalCreateUser(array('access content overview', 'access content')); $this->drupalLogin($user); }
protected function setUp() { parent::setUp(); $this->entityStorage = $this->entityManager->getStorage('entity_test'); $this->factory = $this->container->get('entity.query'); // Add some fieldapi fields to be used in the test. for ($i = 1; $i <= 2; $i++) { $field_name = 'field_test_' . $i; FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'integer', 'cardinality' => 2))->save(); FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test'])->save(); } $entity = $this->entityStorage->create(array('id' => 1, 'user_id' => 1, 'field_test_1' => 1, 'field_test_2' => 2)); $entity->enforceIsNew(); $entity->save(); $entity = $this->entityStorage->create(array('id' => 2, 'user_id' => 2, 'field_test_1' => 1, 'field_test_2' => 7)); $entity->enforceIsNew(); $entity->save(); $entity = $this->entityStorage->create(array('id' => 3, 'user_id' => 2, 'field_test_1' => 2, 'field_test_2' => 1)); $entity->enforceIsNew(); $entity->save(); $entity = $this->entityStorage->create(array('id' => 4, 'user_id' => 2, 'field_test_1' => 2, 'field_test_2' => 8)); $entity->enforceIsNew(); $entity->save(); $entity = $this->entityStorage->create(array('id' => 5, 'user_id' => 3, 'field_test_1' => 2, 'field_test_2' => 2)); $entity->enforceIsNew(); $entity->save(); $entity = $this->entityStorage->create(array('id' => 6, 'user_id' => 3, 'field_test_1' => 3, 'field_test_2' => 8)); $entity->enforceIsNew(); $entity->save(); }
/** * Tests the calculateDependencies method. */ public function testCalculateDependencies() { $comment_type = entity_create('comment_type', array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'node')); $comment_type->save(); $content_type = entity_create('node_type', array('type' => $this->randomMachineName(), 'name' => $this->randomString())); $content_type->save(); $field_storage = entity_create('field_storage_config', array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'node', 'type' => 'comment')); $field_storage->save(); entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', 'settings' => array('comment_type' => $comment_type->id())))->save(); entity_create('field_config', array('field_storage' => FieldStorageConfig::loadByName('node', 'body'), 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_body', 'settings' => array('display_summary' => TRUE)))->save(); $expected = []; $expected['test_field_get_entity'] = ['module' => ['comment', 'node', 'user']]; // Tests dependencies of relationships. $expected['test_relationship_dependency'] = ['module' => ['comment', 'node', 'user']]; $expected['test_plugin_dependencies'] = ['module' => ['comment', 'views_test_data'], 'content' => ['RowTest', 'StaticTest', 'StyleTest']]; $expected['test_argument_dependency'] = ['config' => ['core.entity_view_mode.node.teaser', 'field.storage.node.body'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['node', 'search', 'text', 'user']]; foreach ($this::$testViews as $view_id) { $view = Views::getView($view_id); $dependencies = $view->calculateDependencies(); $this->assertEqual($expected[$view_id], $dependencies); $config = $this->config('views.view.' . $view_id); \Drupal::service('config.storage.staging')->write($view_id, $config->get()); } // Ensure that dependencies are calculated on the display level. $expected_display['default'] = ['config' => ['core.entity_view_mode.node.teaser'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['core', 'node', 'search', 'user', 'views']]; $expected_display['page'] = ['config' => ['field.storage.node.body'], 'module' => ['core', 'text', 'views']]; $view = Views::getView('test_argument_dependency'); $view->initDisplay(); foreach ($view->displayHandlers as $display) { // Calculate the dependencies each display has. $this->assertEqual($expected_display[$display->getPluginId()], $display->calculateDependencies()); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); FilterFormat::create(array('format' => 'my_text_format', 'name' => 'My text format', 'filters' => array('filter_autop' => array('module' => 'filter', 'status' => TRUE))))->save(); FieldStorageConfig::create(array('field_name' => 'formatted_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save(); FieldConfig::create(['entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'formatted_text', 'label' => 'Filtered text'])->save(); }
/** * Tests that a form's action is retained after an Ajax submission. * * The 'action' attribute of a form should not change after an Ajax submission * followed by a non-Ajax submission, which triggers a validation error. */ function testPreserveFormActionAfterAJAX() { // Create a multi-valued field for 'page' nodes to use for Ajax testing. $field_name = 'field_ajax_test'; FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'node', 'type' => 'text', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save(); FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page'])->save(); entity_get_form_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'text_textfield'))->save(); // Log in a user who can create 'page' nodes. $this->webUser = $this->drupalCreateUser(array('create page content')); $this->drupalLogin($this->webUser); // Get the form for adding a 'page' node. Submit an "add another item" Ajax // submission and verify it worked by ensuring the updated page has two text // field items in the field for which we just added an item. $this->drupalGet('node/add/page'); $this->drupalPostAjaxForm(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), NULL, array(), array(), 'node-page-form'); $this->assert(count($this->xpath('//div[contains(@class, "field--name-field-ajax-test")]//input[@type="text"]')) == 2, 'AJAX submission succeeded.'); // Submit the form with the non-Ajax "Save" button, leaving the title field // blank to trigger a validation error, and ensure that a validation error // occurred, because this test is for testing what happens when a form is // re-rendered without being re-built, which is what happens when there's // a validation error. $this->drupalPostForm(NULL, array(), t('Save')); $this->assertText('Title field is required.', 'Non-AJAX submission correctly triggered a validation error.'); // Ensure that the form contains two items in the multi-valued field, so we // know we're testing a form that was correctly retrieved from cache. $this->assert(count($this->xpath('//form[contains(@id, "node-page-form")]//div[contains(@class, "js-form-item-field-ajax-test")]//input[@type="text"]')) == 2, 'Form retained its state from cache.'); // Ensure that the form's action is correct. $forms = $this->xpath('//form[contains(@class, "node-page-form")]'); $this->assertEqual(1, count($forms)); // Strip query params off the action before asserting. $url = parse_url($forms[0]['action'])['path']; $this->assertEqual(Url::fromRoute('node.add', ['node_type' => 'page'])->toString(), $url); }
public function testUserHooks() { FieldStorageConfig::create(array('field_name' => 'field_text', 'type' => 'string', 'entity_type' => 'user'))->save(); FieldConfig::create(array('field_name' => 'field_text', 'type' => 'string', 'entity_type' => 'user', 'bundle' => 'user'))->save(); $this->assertIdentical('', \Drupal::config('name.settings')->get('user_preferred')); FieldStorageConfig::create(array('field_name' => 'field_name_test', 'type' => 'name', 'entity_type' => 'user'))->save(); FieldStorageConfig::create(array('field_name' => 'field_name_test2', 'type' => 'name', 'entity_type' => 'user'))->save(); $field = FieldConfig::create(array('field_name' => 'field_name_test', 'type' => 'name', 'entity_type' => 'user', 'bundle' => 'user')); $field->save(); $field2 = FieldConfig::create(array('field_name' => 'field_name_test2', 'type' => 'name', 'entity_type' => 'user', 'bundle' => 'user')); $field2->save(); $this->assertEqual($field->getName(), \Drupal::config('name.settings')->get('user_preferred')); \Drupal::configFactory()->getEditable('name.settings')->set('user_preferred', $field2->getName())->save(); $field2->delete(); $this->assertEqual('', \Drupal::config('name.settings')->get('user_preferred')); \Drupal::configFactory()->getEditable('name.settings')->set('user_preferred', $field->getName())->save(); $account = User::create(array('name' => 'test')); $account->field_name_test[0] = array('given' => 'Max', 'family' => 'Mustermann'); $account->save(); $account = User::load($account->id()); $this->assertEqual('Max Mustermann', $account->realname); $this->assertEqual('Max Mustermann', user_format_name($account)); $this->assertEqual('test', $account->getUsername()); $this->assertEqual('Max Mustermann', $account->getDisplayName()); }
function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); // Create and login user. $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer languages', 'access administration pages', 'administer content types', 'administer comments', 'create article content', 'access comments', 'post comments', 'skip comment approval')); $this->drupalLogin($admin_user); // Add language. $edit = array('predefined_langcode' => 'fr'); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); // Set "Article" content type to use multilingual support. $edit = array('language_configuration[language_show]' => TRUE); $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); // Enable content language negotiation UI. \Drupal::state()->set('language_test.content_language_type', TRUE); // Set interface language detection to user and content language detection // to URL. Disable inheritance from interface language to ensure content // language will fall back to the default language if no URL language can be // detected. $edit = array('language_interface[enabled][language-user]' => TRUE, 'language_content[enabled][language-url]' => TRUE, 'language_content[enabled][language-interface]' => FALSE); $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); // Change user language preference, this way interface language is always // French no matter what path prefix the URLs have. $edit = array('preferred_langcode' => 'fr'); $this->drupalPostForm("user/" . $admin_user->id() . "/edit", $edit, t('Save')); // Create comment field on article. $this->container->get('comment.manager')->addDefaultField('node', 'article'); // Make comment body translatable. $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $field_storage->translatable = TRUE; $field_storage->save(); $this->assertTrue($field_storage->isTranslatable(), 'Comment body is translatable.'); }
/** * Tests for the presence of nodes on the global tracker listing. */ function testTrackerAll() { $this->drupalLogin($this->user); $unpublished = $this->drupalCreateNode(array('title' => $this->randomMachineName(8), 'status' => 0)); $published = $this->drupalCreateNode(array('title' => $this->randomMachineName(8), 'status' => 1)); $this->drupalGet('activity'); $this->assertNoText($unpublished->label(), 'Unpublished node does not show up in the tracker listing.'); $this->assertText($published->label(), 'Published node shows up in the tracker listing.'); $this->assertLink(t('My recent content'), 0, 'User tab shows up on the global tracker page.'); // Assert cache contexts, specifically the pager and node access contexts. $this->assertCacheContexts(['languages:language_interface', 'theme', 'url.query_args.pagers:0', 'user.node_grants:view', 'user.permissions']); // Assert cache tags for the visible node and node list cache tag. $this->assertCacheTags(Cache::mergeTags($published->getCacheTags(), $published->getOwner()->getCacheTags(), ['node_list', 'rendered'])); // Delete a node and ensure it no longer appears on the tracker. $published->delete(); $this->drupalGet('activity'); $this->assertNoText($published->label(), 'Deleted node does not show up in the tracker listing.'); // Test proper display of time on activity page when comments are disabled. // Disable comments. FieldStorageConfig::loadByName('node', 'comment')->delete(); $node = $this->drupalCreateNode(['title' => 'testing_node_presave', 'status' => 1]); $this->drupalGet('activity'); $this->assertText($node->label(), 'Published node shows up in the tracker listing.'); $this->assertText(\Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime()), 'The changed time was displayed on the tracker listing.'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installConfig(['system']); $this->installConfig(['field']); $this->installConfig(['text']); $this->installConfig(['address']); $this->installEntitySchema('entity_test'); ConfigurableLanguage::createFromLangcode('zh-hant')->save(); // The address module is never installed, so the importer doesn't run // automatically. Instead, we manually import the address formats we need. $country_codes = ['AD', 'SV', 'TW', 'US', 'ZZ']; $importer = \Drupal::service('address.address_format_importer'); $importer->importEntities($country_codes); $importer->importTranslations(['zh-hant']); $this->entityType = 'entity_test'; $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); $field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'address']); $field_storage->save(); $field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName()]); $field->save(); $values = ['targetEntityType' => $this->entityType, 'bundle' => $this->bundle, 'mode' => 'default', 'status' => TRUE]; $this->display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->create($values); $this->display->setComponent($this->fieldName, ['type' => 'address_default', 'settings' => []]); $this->display->save(); }
function setUp() { parent::setUp(); // Create and login user. $test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration')); $this->drupalLogin($test_user); // Add a new language. $language = new Language(array('id' => 'es', 'name' => 'Spanish')); language_save($language); // Make the body field translatable. The title is already translatable by // definition. The parent class has already created the article and page // content types. $field_storage = FieldStorageConfig::loadByName('node', 'body'); $field_storage->translatable = TRUE; $field_storage->save(); // Create a few page nodes with multilingual body values. $default_format = filter_default_format(); $nodes = array(array('title' => 'First node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array('title' => 'Second node this is the Spanish title', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'es'), array('title' => 'Third node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en')); $this->searchable_nodes = array(); foreach ($nodes as $setting) { $this->searchable_nodes[] = $this->drupalCreateNode($setting); } // Add English translation to the second node. $translation = $this->searchable_nodes[1]->addTranslation('en', array('title' => 'Second node en')); $translation->body->value = $this->randomMachineName(32); $this->searchable_nodes[1]->save(); // Add Spanish translation to the third node. $translation = $this->searchable_nodes[2]->addTranslation('es', array('title' => 'Third node es')); $translation->body->value = $this->randomMachineName(32); $this->searchable_nodes[2]->save(); // Update the index and then run the shutdown method. $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $plugin->updateIndex(); search_update_totals(); }