本文整理汇总了PHP中Drupal\node\NodeInterface::getEntityTypeId方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::getEntityTypeId方法的具体用法?PHP NodeInterface::getEntityTypeId怎么用?PHP NodeInterface::getEntityTypeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::getEntityTypeId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConfigurableEventHandler
/**
* Tests ConfigurableEventHandlerEntityBundle.
*
* Test that rules are triggered correctly based upon the fully qualified
* event name as well as the base event name.
*
* @todo Add integrity check that node.field_integer is detected by Rules.
*/
public function testConfigurableEventHandler()
{
// Create rule1 with the 'rules_entity_presave:node--page' event.
$rule1 = $this->expressionManager->createRule();
$rule1->addAction('rules_test_log', ContextConfig::create()->map('message', 'node.field_integer.0.value'));
$config_entity1 = $this->storage->create(['id' => 'test_rule1']);
$config_entity1->set('events', [['event_name' => 'rules_entity_presave:node--page']]);
$config_entity1->set('expression', $rule1->getConfiguration());
$config_entity1->save();
// Create rule2 with the 'rules_entity_presave:node' event.
$rule2 = $this->expressionManager->createRule();
$rule2->addAction('rules_test_log', ContextConfig::create()->map('message', 'node.field_integer.1.value'));
$config_entity2 = $this->storage->create(['id' => 'test_rule2']);
$config_entity2->set('events', [['event_name' => 'rules_entity_presave:node']]);
$config_entity2->set('expression', $rule2->getConfiguration());
$config_entity2->save();
// The logger instance has changed, refresh it.
$this->logger = $this->container->get('logger.channel.rules');
// Add node.field_integer.0.value to rules log message, read result.
$this->node->field_integer->setValue(['0' => 11, '1' => 22]);
// Trigger node save.
$entity_type_id = $this->node->getEntityTypeId();
$event = new EntityEvent($this->node, [$entity_type_id => $this->node]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_presave:{$entity_type_id}", $event);
// Test that the action in the rule1 logged node value.
$this->assertRulesLogEntryExists(11, 1);
// Test that the action in the rule2 logged node value.
$this->assertRulesLogEntryExists(22, 0);
}