本文整理汇总了PHP中Drupal\node\Entity\NodeType::save方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeType::save方法的具体用法?PHP NodeType::save怎么用?PHP NodeType::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\Entity\NodeType
的用法示例。
在下文中一共展示了NodeType::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setup();
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installEntitySchema('entity_test');
$this->nodeType = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomString()]);
$this->nodeType->save();
$this->vocabulary = Vocabulary::create(['vid' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomString()]);
$this->vocabulary->save();
// Create a custom bundle.
$this->customBundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
entity_test_create_bundle($this->customBundle, NULL, 'entity_test');
}
示例2: createNodeType
/**
* Creates a new node_type.
*
* @param string $rdf_type
* URI of the resource.
*/
protected function createNodeType($rdf_type) {
$type = explode(':', $rdf_type);
$type = $this->prefix . $type[1];
// Truncate if machine_name is longer than 32 char.
if (strlen($type) > 32) {
$type = substr($type, 0, 32);
}
$values = array(
'name' => $this->converter->label($rdf_type),
'type' => strtolower($type),
'description' => $this->converter->description($rdf_type),
);
try {
$this->entity = \Drupal::entityTypeManager()->getStorage('node_type')->create($values);
$this->entity->save();
}
catch (\Exception $e) {
drupal_set_message('type', $this->t("Error saving content type %invalid.", array('%invalid' => $rdf_type)));
}
}