本文整理汇总了PHP中Drupal\field\Entity\FieldStorageConfig::save方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldStorageConfig::save方法的具体用法?PHP FieldStorageConfig::save怎么用?PHP FieldStorageConfig::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\field\Entity\FieldStorageConfig
的用法示例。
在下文中一共展示了FieldStorageConfig::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: testBlockFields
/**
* Checks block edit functionality.
*/
public function testBlockFields()
{
$this->drupalLogin($this->adminUser);
$this->blockType = $this->createBlockContentType('link');
// Create a field with settings to validate.
$this->fieldStorage = entity_create('field_storage_config', array('name' => drupal_strtolower($this->randomName()), 'entity_type' => 'block_content', 'type' => 'link', 'cardinality' => 2));
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'link', 'settings' => array('title' => DRUPAL_OPTIONAL)));
$this->instance->save();
entity_get_form_display('block_content', 'link', 'default')->setComponent($this->fieldStorage->getName(), array('type' => 'link_default'))->save();
entity_get_display('block_content', 'link', 'default')->setComponent($this->fieldStorage->getName(), array('type' => 'link', 'label' => 'hidden'))->save();
// Create a block.
$this->drupalGet('block/add/link');
$edit = array('info[0][value]' => $this->randomName(8), $this->fieldStorage->getName() . '[0][url]' => 'http://example.com', $this->fieldStorage->getName() . '[0][title]' => 'Example.com');
$this->drupalPostForm(NULL, $edit, t('Save'));
$block = entity_load('block_content', 1);
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
// Place the block.
$instance = array('id' => drupal_strtolower($edit['info[0][value]']), 'settings[label]' => $edit['info[0][value]'], 'region' => 'sidebar_first');
$this->drupalPostForm($url, $instance, t('Save block'));
// Navigate to home page.
$this->drupalGet('<front>');
$this->assertLinkByHref('http://example.com');
$this->assertText('Example.com');
}
示例3: 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' => 'example@example.com')))->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="example@example.com"');
// Submit a valid email address and ensure it is accepted.
$value = 'test@example.com';
$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');
}
示例4: setUp
function setUp()
{
parent::setUp();
$this->fieldStorageDefinition = array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field');
$this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->fieldDefinition = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test');
}
示例5: setUp
function setUp()
{
parent::setUp();
$this->fieldStorageDefinition = array('name' => drupal_strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field');
$this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->instanceDefinition = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test');
}
示例6: setUp
protected function setUp()
{
parent::setUp();
$this->fieldStorage = FieldStorageConfig::create(array('field_name' => strtolower($this->randomMachineName()), 'entity_type' => 'contact_message', 'type' => 'text'));
$this->fieldStorage->save();
ContactForm::create(['id' => 'contact_message', 'label' => 'Test contact form'])->save();
FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'contact_message'])->save();
$this->container->get('views.views_data')->clear();
}
示例7: setUp
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();
}
示例8: setUp
/**
* {@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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: setUp
function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$entity_type = 'entity_test_rev';
$this->field_name = strtolower($this->randomName());
$this->field_cardinality = 4;
$this->fieldStorage = entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => $this->field_cardinality));
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => $entity_type));
$this->instance->save();
$this->table = ContentEntityDatabaseStorage::_fieldTableName($this->fieldStorage);
$this->revision_table = ContentEntityDatabaseStorage::_fieldRevisionTableName($this->fieldStorage);
}
示例13: 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);
}
示例14: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installConfig(['system']);
$this->installSchema('system', ['sequences', 'key_value']);
// Add a datetime range field.
$this->fieldStorage = FieldStorageConfig::create(['field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'daterange', 'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATE]]);
$this->fieldStorage->save();
$this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE]);
$this->field->save();
$display_options = ['type' => 'daterange_default', 'label' => 'hidden', 'settings' => ['format_type' => 'fallback', 'separator' => 'UNTRANSLATED']];
EntityViewDisplay::create(['targetEntityType' => $this->field->getTargetEntityTypeId(), 'bundle' => $this->field->getTargetBundle(), 'mode' => 'default', 'status' => TRUE])->setComponent($this->fieldStorage->getName(), $display_options)->save();
}
示例15: setUp
protected function setUp()
{
parent::setUp();
$this->installConfig(array('language'));
$this->field_name = drupal_strtolower($this->randomMachineName());
$this->entity_type = 'entity_test';
$this->field_storage_definition = array('field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4, 'translatable' => TRUE);
$this->fieldStorage = entity_create('field_storage_config', $this->field_storage_definition);
$this->fieldStorage->save();
$this->field_definition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test');
$this->field = entity_create('field_config', $this->field_definition);
$this->field->save();
for ($i = 0; $i < 3; ++$i) {
ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
}
}