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


PHP FieldConfig::loadByName方法代码示例

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


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

示例1: testNodeType

 /**
  * Tests Drupal 6 node type to Drupal 8 migration.
  */
 public function testNodeType()
 {
     $migration = entity_load('migration', 'd6_node_type');
     // Test the test_page content type.
     $node_type_page = NodeType::load('test_page');
     $this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded');
     $this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
     $this->assertIdentical(FALSE, $node_type_page->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_page')), array('test_page'));
     // Test we have a body field.
     $field = FieldConfig::loadByName('node', 'test_page', 'body');
     $this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
     // Test the test_story content type.
     $node_type_story = NodeType::load('test_story');
     $this->assertIdentical('test_story', $node_type_story->id(), 'Node type test_story loaded');
     $this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
     $this->assertIdentical(FALSE, $node_type_story->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_story')), array('test_story'));
     // Test we don't have a body field.
     $field = FieldConfig::loadByName('node', 'test_story', 'body');
     $this->assertIdentical(NULL, $field, 'No body field found');
     // Test the test_event content type.
     $node_type_event = NodeType::load('test_event');
     $this->assertIdentical('test_event', $node_type_event->id(), 'Node type test_event loaded');
     $this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
     $this->assertIdentical(TRUE, $node_type_event->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_event')), array('test_event'));
     // Test we have a body field.
     $field = FieldConfig::loadByName('node', 'test_event', 'body');
     $this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:37,代码来源:MigrateNodeTypeTest.php

示例2: prepareTranslationSuggestions

 /**
  * Prepare a node to get suggestions from.
  *
  * Creates a node with two file fields. The first one is not translatable,
  * the second one is. Both fields got two files attached, where one has
  * translatable content (title and atl-text) and the other one not.
  *
  * @return object
  *   The node which is prepared with all needed fields for the suggestions.
  */
 protected function prepareTranslationSuggestions()
 {
     // Create a content type with fields.
     // Only the first field is a translatable reference.
     $type = NodeType::create(['type' => $this->randomMachineName()]);
     $type->save();
     $content_translation_manager = \Drupal::service('content_translation.manager');
     $content_translation_manager->setEnabled('node', $type->id(), TRUE);
     $field1 = FieldStorageConfig::create(array('field_name' => 'field1', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field1->save();
     $field2 = FieldStorageConfig::create(array('field_name' => 'field2', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field2->save();
     // Create field instances on the content type.
     FieldConfig::create(array('field_storage' => $field1, 'bundle' => $type->id(), 'label' => 'Field 1', 'translatable' => FALSE, 'settings' => array()))->save();
     FieldConfig::create(array('field_storage' => $field2, 'bundle' => $type->id(), 'label' => 'Field 2', 'translatable' => TRUE, 'settings' => array()))->save();
     // Create a translatable body field.
     node_add_body_field($type);
     $field = FieldConfig::loadByName('node', $type->id(), 'body');
     $field->setTranslatable(TRUE);
     $field->save();
     // Create 4 nodes to be referenced.
     $references = array();
     for ($i = 0; $i < 4; $i++) {
         $references[$i] = Node::create(array('title' => $this->randomMachineName(), 'body' => $this->randomMachineName(), 'type' => $type->id()));
         $references[$i]->save();
     }
     // Create a node with two translatable and two non-translatable references.
     $node = Node::create(array('title' => $this->randomMachineName(), 'type' => $type->id(), 'language' => 'en', 'body' => $this->randomMachineName(), $field1->getName() => array(array('target_id' => $references[0]->id()), array('target_id' => $references[1]->id())), $field2->getName() => array(array('target_id' => $references[2]->id()), array('target_id' => $references[3]->id()))));
     $node->save();
     $link = MenuLinkContent::create(['link' => [['uri' => 'entity:node/' . $node->id()]], 'title' => 'Node menu link', 'menu_name' => 'main']);
     $link->save();
     $node->link = $link;
     return $node;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:44,代码来源:ContentEntitySuggestionsTest.php

示例3: testRequired

 /**
  * Tests the required property on file fields.
  */
 function testRequired()
 {
     $type_name = 'article';
     $field_name = strtolower($this->randomMachineName());
     $storage = $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1'));
     $field = FieldConfig::loadByName('node', $type_name, $field_name);
     $test_file = $this->getTestFile('text');
     // Try to post a new node without uploading a file.
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName();
     $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish'));
     $this->assertRaw(t('!title field is required.', array('!title' => $field->getLabel())), 'Node save failed when required file field was empty.');
     // Create a new node with the uploaded file.
     $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
     $this->assertTrue($nid !== FALSE, format_string('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name)));
     $node = node_load($nid, TRUE);
     $node_file = file_load($node->{$field_name}->target_id);
     $this->assertFileExists($node_file, 'File exists after uploading to the required field.');
     $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.');
     // Try again with a multiple value field.
     $storage->delete();
     $this->createFileField($field_name, 'node', $type_name, array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), array('required' => '1'));
     // Try to post a new node without uploading a file in the multivalue field.
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName();
     $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish'));
     $this->assertRaw(t('!title field is required.', array('!title' => $field->getLabel())), 'Node save failed when required multiple value file field was empty.');
     // Create a new node with the uploaded file into the multivalue field.
     $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
     $node = node_load($nid, TRUE);
     $node_file = file_load($node->{$field_name}->target_id);
     $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.');
     $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:FileFieldValidateTest.php

示例4: setUp

 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'));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:26,代码来源:EditorLoadingTest.php

示例5: testNodeTypeEditing

 /**
  * Tests editing a node type using the UI.
  */
 function testNodeTypeEditing()
 {
     $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields'));
     $this->drupalLogin($web_user);
     $field = FieldConfig::loadByName('node', 'page', 'body');
     $this->assertEqual($field->getLabel(), 'Body', 'Body field was found.');
     // Verify that title and body fields are displayed.
     $this->drupalGet('node/add/page');
     $this->assertRaw('Title', 'Title field was found.');
     $this->assertRaw('Body', 'Body field was found.');
     // Rename the title field.
     $edit = array('title_label' => 'Foo');
     $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->drupalGet('node/add/page');
     $this->assertRaw('Foo', 'New title label was displayed.');
     $this->assertNoRaw('Title', 'Old title label was not displayed.');
     // Change the name, machine name and description.
     $edit = array('name' => 'Bar', 'type' => 'bar', 'description' => 'Lorem ipsum.');
     $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
     $this->drupalGet('node/add');
     $this->assertRaw('Bar', 'New name was displayed.');
     $this->assertRaw('Lorem ipsum', 'New description was displayed.');
     $this->clickLink('Bar');
     $this->assertUrl(\Drupal::url('node.add', ['node_type' => 'bar'], ['absolute' => TRUE]), [], 'New machine name was used in URL.');
     $this->assertRaw('Foo', 'Title field was found.');
     $this->assertRaw('Body', 'Body field was found.');
     // Remove the body field.
     $this->drupalPostForm('admin/structure/types/manage/bar/fields/node.bar.body/delete', array(), t('Delete'));
     // Resave the settings for this type.
     $this->drupalPostForm('admin/structure/types/manage/bar', array(), t('Save content type'));
     // Check that the body field doesn't exist.
     $this->drupalGet('node/add/bar');
     $this->assertNoRaw('Body', 'Body field was not found.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:NodeTypeTest.php

示例6: testImport

 /**
  * Tests that importing list_float fields works.
  */
 public function testImport()
 {
     $field_name = 'field_options_float';
     $type = 'options_install_test';
     // Test the results on installing options_config_install_test. All the
     // necessary configuration for this test is created by installing that
     // module.
     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
     $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
     $admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage';
     // Export active config to sync.
     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
     // Set the active to not use dots in the allowed values key names.
     $edit = array('settings[allowed_values]' => "0|Zero\n1|One");
     $this->drupalPostForm($admin_path, $edit, t('Save field settings'));
     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
     $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '1' => 'One'));
     // Import configuration with dots in the allowed values key names. This
     // tests \Drupal\Core\Config\Entity\ConfigEntityStorage::importUpdate().
     $this->drupalGet('admin/config/development/configuration');
     $this->drupalPostForm(NULL, array(), t('Import all'));
     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
     $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
     // Delete field to test creation. This tests
     // \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate().
     FieldConfig::loadByName('node', $type, $field_name)->delete();
     $this->drupalGet('admin/config/development/configuration');
     $this->drupalPostForm(NULL, array(), t('Import all'));
     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
     $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:34,代码来源:OptionsFloatFieldImportTest.php

示例7: testUserSelectionByRole

 /**
  * Tests user selection by roles.
  */
 function testUserSelectionByRole()
 {
     $field_definition = FieldConfig::loadByName('user', 'user', 'user_reference');
     $handler_settings = $field_definition->getSetting('handler_settings');
     $handler_settings['filter']['role'] = array($this->role1->id() => $this->role1->id(), $this->role2->id() => 0);
     $handler_settings['filter']['type'] = 'role';
     $field_definition->setSetting('handler_settings', $handler_settings);
     $field_definition->save();
     $user1 = $this->createUser(array('name' => 'aabb'));
     $user1->addRole($this->role1->id());
     $user1->save();
     $user2 = $this->createUser(array('name' => 'aabbb'));
     $user2->addRole($this->role1->id());
     $user2->save();
     $user3 = $this->createUser(array('name' => 'aabbbb'));
     $user3->addRole($this->role2->id());
     $user3->save();
     /** @var \Drupal\Core\Entity\EntityAutocompleteMatcher $autocomplete */
     $autocomplete = \Drupal::service('entity.autocomplete_matcher');
     $matches = $autocomplete->getMatches('user', 'default', $field_definition->getSetting('handler_settings'), 'aabb');
     $this->assertEqual(count($matches), 2);
     $users = array();
     foreach ($matches as $match) {
         $users[] = $match['label'];
     }
     $this->assertTrue(in_array($user1->label(), $users));
     $this->assertTrue(in_array($user2->label(), $users));
     $this->assertFalse(in_array($user3->label(), $users));
     $matches = $autocomplete->getMatches('user', 'default', $field_definition->getSetting('handler_settings'), 'aabbbb');
     $this->assertEqual(count($matches), 0, '');
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:34,代码来源:UserEntityReferenceTest.php

示例8: testCommentDefaultFields

 /**
  * Tests that the default 'comment_body' field is correctly added.
  */
 function testCommentDefaultFields()
 {
     // Do not make assumptions on default node types created by the test
     // installation profile, and create our own.
     $this->drupalCreateContentType(array('type' => 'test_node_type'));
     $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type');
     // Check that the 'comment_body' field is present on the comment bundle.
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
     $this->assertTrue(!empty($field), 'The comment_body field is added when a comment bundle is created');
     $field->delete();
     // Check that the 'comment_body' field is deleted.
     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
     $this->assertTrue(empty($field_storage), 'The comment_body field was deleted');
     // Create a new content type.
     $type_name = 'test_node_type_2';
     $this->drupalCreateContentType(array('type' => $type_name));
     $this->container->get('comment.manager')->addDefaultField('node', $type_name);
     // Check that the 'comment_body' field exists and has an instance on the
     // new comment bundle.
     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
     $this->assertTrue($field_storage, 'The comment_body field exists');
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
     $this->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
     // Test adding a field that defaults to CommentItemInterface::CLOSED.
     $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
     $field = entity_load('field_config', 'node.test_node_type.who_likes_ponies');
     $this->assertEqual($field->default_value[0]['status'], CommentItemInterface::CLOSED);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:31,代码来源:CommentFieldsTest.php

示例9: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     // Load two modules: the captcha module itself and the comment
     // module for testing anonymous comments.
     parent::setUp();
     module_load_include('inc', 'captcha');
     $this->drupalCreateContentType(array('type' => 'page'));
     // Create a normal user.
     $permissions = array('access comments', 'post comments', 'skip comment approval', 'access content', 'create page content', 'edit own page content');
     $this->normalUser = $this->drupalCreateUser($permissions);
     // Create an admin user.
     $permissions[] = 'administer CAPTCHA settings';
     $permissions[] = 'skip CAPTCHA';
     $permissions[] = 'administer permissions';
     $permissions[] = 'administer content types';
     $this->adminUser = $this->drupalCreateUser($permissions);
     // Open comment for page content type.
     $this->addDefaultCommentField('node', 'page');
     // Put comments on page nodes on a separate page.
     $comment_field = FieldConfig::loadByName('node', 'page', 'comment');
     $comment_field->setSetting('form_location', CommentItemInterface::FORM_SEPARATE_PAGE);
     $comment_field->save();
     /* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
     $captcha_point = \Drupal::entityManager()->getStorage('captcha_point')->load('user_login_form');
     $captcha_point->enable()->save();
     $this->config('captcha.settings')->set('default_challenge', 'captcha/test')->save();
 }
开发者ID:Wylbur,项目名称:gj,代码行数:30,代码来源:CaptchaBaseWebTestCase.php

示例10: postComment

 /**
  * Posts a comment.
  *
  * @param \Drupal\Core\Entity\EntityInterface|null $entity
  *   Entity to post comment on or NULL to post to the previously loaded page.
  * @param string $comment
  *   Comment body.
  * @param string $subject
  *   Comment subject.
  * @param mixed $contact
  *   Set to NULL for no contact info, TRUE to ignore success checking, and
  *   array of values to set contact info.
  *
  * @return \Drupal\comment\CommentInterface
  *   The new comment entity.
  */
 function postComment(EntityInterface $entity, $comment, $subject = '', $contact = NULL)
 {
     $edit = array();
     $edit['comment_body[0][value]'] = $comment;
     $field = FieldConfig::loadByName('entity_test', 'entity_test', 'comment');
     $preview_mode = $field->getSetting('preview');
     // Must get the page before we test for fields.
     if ($entity !== NULL) {
         $this->drupalGet('comment/reply/entity_test/' . $entity->id() . '/comment');
     }
     // Determine the visibility of subject form field.
     if (entity_get_form_display('comment', 'comment', 'default')->getComponent('subject')) {
         // Subject input allowed.
         $edit['subject[0][value]'] = $subject;
     } else {
         $this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
     }
     if ($contact !== NULL && is_array($contact)) {
         $edit += $contact;
     }
     switch ($preview_mode) {
         case DRUPAL_REQUIRED:
             // Preview required so no save button should be found.
             $this->assertNoFieldByName('op', t('Save'), 'Save button not found.');
             $this->drupalPostForm(NULL, $edit, t('Preview'));
             // Don't break here so that we can test post-preview field presence and
             // function below.
         // Don't break here so that we can test post-preview field presence and
         // function below.
         case DRUPAL_OPTIONAL:
             $this->assertFieldByName('op', t('Preview'), 'Preview button found.');
             $this->assertFieldByName('op', t('Save'), 'Save button found.');
             $this->drupalPostForm(NULL, $edit, t('Save'));
             break;
         case DRUPAL_DISABLED:
             $this->assertNoFieldByName('op', t('Preview'), 'Preview button not found.');
             $this->assertFieldByName('op', t('Save'), 'Save button found.');
             $this->drupalPostForm(NULL, $edit, t('Save'));
             break;
     }
     $match = array();
     // Get comment ID
     preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
     // Get comment.
     if ($contact !== TRUE) {
         // If true then attempting to find error message.
         if ($subject) {
             $this->assertText($subject, 'Comment subject posted.');
         }
         $this->assertText($comment, 'Comment body posted.');
         $this->assertTrue(!empty($match) && !empty($match[1]), 'Comment ID found.');
     }
     if (isset($match[1])) {
         return Comment::load($match[1]);
     }
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:72,代码来源:CommentNonNodeTest.php

示例11: createEntityReferenceField

 /**
  * Creates a field of an entity reference field storage on the specified bundle.
  *
  * @param string $entity_type
  *   The type of entity the field will be attached to.
  * @param string $bundle
  *   The bundle name of the entity the field will be attached to.
  * @param string $field_name
  *   The name of the field; if it already exists, a new instance of the existing
  *   field will be created.
  * @param string $field_label
  *   The label of the field.
  * @param string $target_entity_type
  *   The type of the referenced entity.
  * @param string $selection_handler
  *   The selection handler used by this field.
  * @param array $selection_handler_settings
  *   An array of settings supported by the selection handler specified above.
  *   (e.g. 'target_bundles', 'sort', 'auto_create', etc).
  * @param int $cardinality
  *   The cardinality of the field.
  *
  * @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm()
  */
 protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1)
 {
     // Look for or add the specified field to the requested entity bundle.
     if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
         FieldStorageConfig::create(array('field_name' => $field_name, 'type' => 'entity_reference', 'entity_type' => $entity_type, 'cardinality' => $cardinality, 'settings' => array('target_type' => $target_entity_type)))->save();
     }
     if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
         FieldConfig::create(array('field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'label' => $field_label, 'settings' => array('handler' => $selection_handler, 'handler_settings' => $selection_handler_settings)))->save();
     }
 }
开发者ID:dev981,项目名称:gaptest,代码行数:34,代码来源:EntityReferenceTestTrait.php

示例12: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
     $this->vocabulary = $this->createVocabulary();
     $field_name = 'taxonomy_' . $this->vocabulary->id();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     $this->field = FieldConfig::loadByName('node', 'article', $field_name);
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'options_select'))->save();
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_label'))->save();
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:12,代码来源:TermTest.php

示例13: testFieldOverrides

 /**
  * Tests node body field storage persistence even if there are no instances.
  */
 public function testFieldOverrides()
 {
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertTrue($field_storage, 'Node body field storage exists.');
     $type = NodeType::create(['name' => 'Ponies', 'type' => 'ponies']);
     $type->save();
     node_add_body_field($type);
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertTrue(count($field_storage->getBundles()) == 1, 'Node body field storage is being used on the new node type.');
     $field = FieldConfig::loadByName('node', 'ponies', 'body');
     $field->delete();
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertTrue(count($field_storage->getBundles()) == 0, 'Node body field storage exists after deleting the only instance of a field.');
     \Drupal::service('module_installer')->uninstall(array('node'));
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertFalse($field_storage, 'Node body field storage does not exist after uninstalling the Node module.');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:20,代码来源:NodeBodyFieldStorageTest.php

示例14: testMarkFieldForDeletion

 /**
  * Test that a field set to an empty array is different than an absent field.
  */
 public function testMarkFieldForDeletion()
 {
     // Add a default value for a field.
     $field = FieldConfig::loadByName('entity_test', 'entity_test', 'field_test_text');
     $field->setDefaultValue(array(array('value' => 'Llama')));
     $field->save();
     // Denormalize data that contains no entry for the field, and check that
     // the default value is present in the resulting entity.
     $data = array('_links' => array('type' => array('href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString())));
     $entity = $this->serializer->denormalize($data, $this->entityClass, $this->format);
     $this->assertEqual($entity->field_test_text->count(), 1);
     $this->assertEqual($entity->field_test_text->value, 'Llama');
     // Denormalize data that contains an empty entry for the field, and check
     // that the field is empty in the resulting entity.
     $data = array('_links' => array('type' => array('href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString())), 'field_test_text' => array());
     $entity = $this->serializer->denormalize($data, get_class($entity), $this->format, ['target_instance' => $entity]);
     $this->assertEqual($entity->field_test_text->count(), 0);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:21,代码来源:DenormalizeTest.php

示例15: testImportCreate

 /**
  * Tests creating a content type during config import.
  */
 public function testImportCreate()
 {
     $node_type_id = 'import';
     $node_type_config_name = "node.type.{$node_type_id}";
     // Simulate config data to import.
     $active = $this->container->get('config.storage');
     $sync = $this->container->get('config.storage.sync');
     $this->copyConfig($active, $sync);
     // Manually add new node type.
     $src_dir = __DIR__ . '/../../../modules/node_test_config/sync';
     $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$node_type_config_name}.yml", "{$target_dir}/{$node_type_config_name}.yml"));
     // Import the content of the sync directory.
     $this->configImporter()->import();
     // Check that the content type was created.
     $node_type = NodeType::load($node_type_id);
     $this->assertTrue($node_type, 'Import node type from sync was created.');
     $this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body'));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:22,代码来源:NodeImportCreateTest.php


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