本文整理汇总了PHP中node_add_body_field函数的典型用法代码示例。如果您正苦于以下问题:PHP node_add_body_field函数的具体用法?PHP node_add_body_field怎么用?PHP node_add_body_field使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了node_add_body_field函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: setUp
public function setUp() {
parent::setup();
$this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->installSchema('node', array('node_access'));
$this->installSchema('system', array('url_alias', 'sequences', 'router'));
$type = NodeType::create(['type' => 'page']);
$type->save();
node_add_body_field($type);
$this->nodePattern = $this->createPattern('node', '/content/[node:title]');
$this->userPattern = $this->createPattern('user', '/users/[user:name]');
\Drupal::service('router.builder')->rebuild();
$this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
$this->currentUser->save();
}
示例3: webformUserCreateType
/**
* Create a petition content type and webform user enable it.
*/
protected function webformUserCreateType()
{
$type = node_type_set_defaults();
$type->name = t('Petition');
$type->type = 'petition';
$type->description = t('Webform user petition type.');
$type->title_label = t('Title');
$type->has_title = $type->title_label != '';
$type->base = 'node_content';
$type->custom = TRUE;
$type->modified = TRUE;
// Save or reset persistent variable values.
$variables = array('node_submitted' => 0, 'comment' => COMMENT_NODE_HIDDEN, 'webform_user' => 1, 'webform_user_default_fields' => array('webform_user_all_profile_fields' => 'webform_user_all_profile_fields'));
foreach ($variables as $key => $value) {
$variable_new = $key . '_' . $type->type;
if (is_array($value)) {
$value = array_keys(array_filter($value));
}
variable_set($variable_new, $value);
}
$status = node_type_save($type);
node_types_rebuild();
node_add_body_field($type);
// Add as a webform.
$webform_node_types = variable_get('webform_node_types', array('webform'));
$webform_node_types_primary = variable_get('webform_node_types_primary', array('webform'));
$webform_node_types = array_merge($webform_node_types, array('petition'));
$webform_node_types_primary = array_merge($webform_node_types_primary, array('petition'));
variable_set('webform_node_types', array_unique($webform_node_types));
variable_set('webform_node_types_primary', array_unique($webform_node_types_primary));
}
示例4: testRecreateEntity
public function testRecreateEntity()
{
$type_name = Unicode::strtolower($this->randomMachineName(16));
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
$content_type->save();
node_add_body_field($content_type);
/** @var \Drupal\Core\Config\StorageInterface $active */
$active = $this->container->get('config.storage');
/** @var \Drupal\Core\Config\StorageInterface $sync */
$sync = $this->container->get('config.storage.sync');
$config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
$this->copyConfig($active, $sync);
// Delete the content type. This will also delete a field storage, a field,
// an entity view display and an entity form display.
$content_type->delete();
$this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
// Recreate with the same type - this will have a different UUID.
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
$content_type->save();
node_add_body_field($content_type);
$this->configImporter->reset();
// A node type, a field, an entity view display and an entity form display
// will be recreated.
$creates = $this->configImporter->getUnprocessedConfiguration('create');
$deletes = $this->configImporter->getUnprocessedConfiguration('delete');
$this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
$this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
$this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
$this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
$this->configImporter->import();
// Verify that there is nothing more to import.
$this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
$content_type = NodeType::load($type_name);
$this->assertEqual('Node type one', $content_type->label());
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('node');
$this->installConfig(['node']);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
// Create a new user which needs to have UID 1, because that is expected by
// the assertions from
// \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
$node_type = entity_create('node_type', array('type' => 'test_planet'));
$node_type->save();
node_add_body_field($node_type);
$node_type = entity_create('node_type', array('type' => 'story'));
$node_type->save();
node_add_body_field($node_type);
$id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))), 'd6_user' => array(array(array(1), array(1)), array(array(2), array(2))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))));
$this->prepareMigrations($id_mappings);
$migration = entity_load('migration', 'd6_node_settings');
$migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
// Create a test node.
$node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1, 'revision_log' => '', 'title' => $this->randomString()));
$node->enforceIsNew();
$node->save();
$node = entity_create('node', array('type' => 'test_planet', 'nid' => 3, 'vid' => 4, 'revision_log' => '', 'title' => $this->randomString()));
$node->enforceIsNew();
$node->save();
}
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installConfig(array('filter', 'node'));
$node_type = entity_create('node_type', array('type' => 'article', 'name' => 'Article'));
$node_type->save();
node_add_body_field($node_type);
}
示例7: createTestContentType
/**
* Create test content type.
*/
protected static function createTestContentType()
{
$name = self::randomName(8);
$type = (object) array('type' => $name, 'name' => $name, 'base' => 'node_content', 'description' => '', 'help' => '', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1, 'orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0);
node_type_save($type);
node_types_rebuild();
node_add_body_field($type);
self::$contentType = $type;
}
示例8: import
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array())
{
$entity_ids = parent::import($row, $old_destination_id_values);
if ($row->getDestinationProperty('create_body')) {
$node_type = $this->storage->load(reset($entity_ids));
node_add_body_field($node_type, $row->getDestinationProperty('create_body_label'));
}
return $entity_ids;
}
示例9: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$node_type = entity_create('node_type', array('type' => 'story'));
$node_type->save();
node_add_body_field($node_type);
$id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))));
$this->prepareIdMappings($id_mappings);
// Create a test node.
$node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1));
$node->enforceIsNew();
$node->save();
// Load dumps.
$dumps = array($this->getDumpDirectory() . '/Drupal6Node.php', $this->getDumpDirectory() . '/Drupal6NodeType.php', $this->getDumpDirectory() . '/Drupal6FieldInstance.php');
$this->loadDumps($dumps);
}
示例10: setUp
public function setUp()
{
parent::setup();
$this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installSchema('node', array('node_access'));
$this->installSchema('system', array('url_alias', 'sequences', 'router'));
$type = NodeType::create(['type' => 'page']);
$type->save();
node_add_body_field($type);
\Drupal::service('router.builder')->rebuild();
$this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
$this->currentUser->save();
}
示例11: 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.');
}
示例12: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('file');
$this->installSchema('node', array('node_access'));
$this->installSchema('file', array('file_usage'));
$this->installConfig(['node']);
// 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();
// Set up text editor.
$editor = entity_create('editor', array('format' => 'filtered_html', 'editor' => 'unicorn'));
$editor->save();
// Create a node type for testing.
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page'));
$type->save();
node_add_body_field($type);
}
示例13: setUp
/**
* {@inheritdoc}
*/
public function setUp($processor = NULL)
{
parent::setUp('rendered_item');
// Load configuration and needed schemas. (The necessary schemas for using
// nodes are already installed by the parent method.)
$this->installConfig(array('system', 'filter', 'node', 'comment'));
$this->installSchema('system', array('router'));
\Drupal::service('router.builder')->rebuild();
// Create a node type for testing.
$type = NodeType::create(array('type' => 'page', 'name' => 'page'));
$type->save();
node_add_body_field($type);
// Create anonymous user role.
$role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
$role->save();
// Insert the anonymous user into the database.
$anonymous_user = User::create(array('uid' => 0, 'name' => ''));
$anonymous_user->save();
// Default node values for all nodes we create below.
$node_data = array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => '', 'body' => array('value' => '', 'summary' => '', 'format' => 'plain_text'), 'uid' => $anonymous_user->id());
// Create some test nodes with valid user on it for rendering a picture.
$node_data['title'] = 'Title for node 1';
$node_data['body']['value'] = 'value for node 1';
$node_data['body']['summary'] = 'summary for node 1';
$this->nodes[1] = Node::create($node_data);
$this->nodes[1]->save();
$node_data['title'] = 'Title for node 2';
$node_data['body']['value'] = 'value for node 2';
$node_data['body']['summary'] = 'summary for node 2';
$this->nodes[2] = Node::create($node_data);
$this->nodes[2]->save();
// Set proper configuration for the tested processor.
$config = $this->processor->getConfiguration();
$config['view_mode'] = array('entity:node' => ['page' => 'full', 'article' => 'teaser'], 'entity:user' => 'compact', 'entity:comment' => 'teaser');
$config['roles'] = array($role->id());
$this->processor->setConfiguration($config);
$this->index->save();
$this->index->getDatasources();
// Enable the classy theme as the tests rely on markup from that.
\Drupal::service('theme_handler')->install(array('classy'));
\Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('classy'));
}
示例14: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('file');
$this->installSchema('node', array('node_access'));
$this->installSchema('file', array('file_usage'));
$this->installConfig(['node']);
// Add text formats.
$filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
$filtered_html_format->save();
// Set cardinality for body field.
FieldStorageConfig::loadByName('node', 'body')->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)->save();
// Set up text editor.
$editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn']);
$editor->save();
// Create a node type for testing.
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save();
node_add_body_field($type);
}
示例15: setUp
/**
* Sets up the test.
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('file');
$this->installSchema('system', ['key_value_expire']);
$this->installSchema('node', array('node_access'));
$this->installSchema('file', array('file_usage'));
$this->installConfig(['node']);
// Add text formats.
$this->format = FilterFormat::create(['format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => ['filter_align' => ['status' => TRUE], 'filter_caption' => ['status' => TRUE]]]);
$this->format->save();
// Set up text editor.
$editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn', 'image_upload' => ['max_size' => 100, 'scheme' => 'public', 'directory' => '', 'status' => TRUE]]);
$editor->save();
// Create a node type for testing.
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save();
node_add_body_field($type);
$this->installEntitySchema('user');
\Drupal::service('router.builder')->rebuild();
}