本文整理汇总了PHP中Drupal\field\Entity\FieldStorageConfig类的典型用法代码示例。如果您正苦于以下问题:PHP FieldStorageConfig类的具体用法?PHP FieldStorageConfig怎么用?PHP FieldStorageConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldStorageConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testBooleanField
/**
* 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);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:63,代码来源:BooleanFieldTest.php
示例2: testEmailField
/**
* 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' => '[email protected]')))->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="[email protected]"');
// Submit a valid email address and ensure it is accepted.
$value = '[email protected]';
$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:[email protected]');
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:34,代码来源:EmailFieldTest.php
示例3: buildRow
/**
* 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;
}
开发者ID:drugo32,项目名称:field_permissions,代码行数:31,代码来源:FieldPermissionsController.php
示例4: hook_rdf_apply_default_fields_alter
/**
* 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';
}
}
}
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:20,代码来源:rdf_entity.api.php
示例5: setUp
/**
* {@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();
}
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:14,代码来源:OptionsFieldUnitTestBase.php
示例6: testUriField
/**
* 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();
}
开发者ID:HakS,项目名称:drupal8_training,代码行数:15,代码来源:UriItemTest.php
示例7: createField
/**
* 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();
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:16,代码来源:DateTestBase.php
示例8: setUp
/**
* {@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);
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:18,代码来源:FieldGroupRowsWebTest.php
示例9: setupTestFields
/**
* 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();
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:ContentTranslationSyncImageTest.php
示例10: setUp
function setUp()
{
parent::setUp();
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up term names.
$this->termNames = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
// Create a vocabulary.
$this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']);
$this->vocabulary->save();
// Add a translatable field to the vocabulary.
$field = FieldStorageConfig::create(array('field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'type' => 'text'));
$field->save();
FieldConfig::create(['field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'label' => 'Foo', 'bundle' => 'views_testing_tags'])->save();
// Create term with translations.
$taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']));
foreach (array('es', 'fr') as $langcode) {
$translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode]));
$translation->description->value = $this->termNames[$langcode];
$translation->field_foo->value = $this->termNames[$langcode];
}
$taxonomy->save();
Views::viewsData()->clear();
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
$this->container->get('router.builder')->rebuild();
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:27,代码来源:TaxonomyFieldFilterTest.php
示例11: setUp
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();
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:7,代码来源:TestItemTest.php
示例12: setUp
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();
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:29,代码来源:PagePreviewTest.php
示例13: testEntityFormLanguage
/**
* 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}.");
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:63,代码来源:EntityTranslationFormTest.php
示例14: testUserProfileFields
/**
* 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']);
}
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:35,代码来源:MigrateUserProfileFieldTest.php
示例15: 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
示例16: orphans
/**
* 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;
}
开发者ID:pedrocones,项目名称:hydrotools,代码行数:33,代码来源:CatalogAdminController.php
示例17: field_post_update_save_custom_storage_property
/**
* 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.');
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:field.post_update.php
示例18: setUp
/**
* {@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);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:36,代码来源:NodeLanguageTest.php
示例19: setUp
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();
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:EntityQueryAggregateTest.php
示例20: testCalculateDependencies
/**
* 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());
}
}
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:36,代码来源:ViewEntityDependenciesTest.php
注:本文中的Drupal\field\Entity\FieldStorageConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论