本文整理匯總了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)));
}
}