node.eval.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * @file
  4. * Contains rules integration for the node module needed during evaluation.
  5. *
  6. * @addtogroup rules
  7. * @{
  8. */
  9. /**
  10. * Base class providing node condition defaults.
  11. */
  12. abstract class RulesNodeConditionBase extends RulesConditionHandlerBase {
  13. public static function defaults() {
  14. return array(
  15. 'parameter' => array(
  16. 'node' => array('type' => 'node', 'label' => t('Content')),
  17. ),
  18. 'category' => 'node',
  19. 'access callback' => 'rules_node_integration_access',
  20. );
  21. }
  22. }
  23. /**
  24. * Condition: Check for selected content types
  25. */
  26. class RulesNodeConditionType extends RulesNodeConditionBase {
  27. /**
  28. * Defines the condition.
  29. */
  30. public static function getInfo() {
  31. $info = self::defaults() + array(
  32. 'name' => 'node_is_of_type',
  33. 'label' => t('Content is of type'),
  34. 'help' => t('Evaluates to TRUE if the given content is of one of the selected content types.'),
  35. );
  36. $info['parameter']['type'] = array(
  37. 'type' => 'list<text>',
  38. 'label' => t('Content types'),
  39. 'options list' => 'node_type_get_names',
  40. 'description' => t('The content type(s) to check for.'),
  41. 'restriction' => 'input',
  42. );
  43. return $info;
  44. }
  45. /**
  46. * Executes the condition.
  47. */
  48. public function execute($node, $types) {
  49. return in_array($node->type, $types);
  50. }
  51. /**
  52. * Provides the content type of a node as asserted metadata.
  53. */
  54. function assertions() {
  55. return array('node' => array('bundle' => $this->element->settings['type']));
  56. }
  57. }
  58. /**
  59. * Condition: Check if the node is published.
  60. */
  61. class RulesNodeConditionPublished extends RulesNodeConditionBase {
  62. /**
  63. * Defines the condition.
  64. */
  65. public static function getInfo() {
  66. return self::defaults() + array(
  67. 'name' => 'node_is_published',
  68. 'label' => t('Content is published'),
  69. );
  70. }
  71. /**
  72. * Executes the condition.
  73. */
  74. public function execute($node) {
  75. return $node->status == 1;
  76. }
  77. }
  78. /**
  79. * Condition: Check if the node is sticky.
  80. */
  81. class RulesNodeConditionSticky extends RulesNodeConditionBase {
  82. /**
  83. * Defines the condition.
  84. */
  85. public static function getInfo() {
  86. return self::defaults() + array(
  87. 'name' => 'node_is_sticky',
  88. 'label' => t('Content is sticky'),
  89. );
  90. }
  91. /**
  92. * Executes the condition.
  93. */
  94. public function execute($node) {
  95. return $node->sticky == 1;
  96. }
  97. }
  98. /**
  99. * Condition: Check if the node is promoted to the frontpage
  100. */
  101. class RulesNodeConditionPromoted extends RulesNodeConditionBase {
  102. /**
  103. * Defines the condition.
  104. */
  105. public static function getInfo() {
  106. return self::defaults() + array(
  107. 'name' => 'node_is_promoted',
  108. 'label' => t('Content is promoted to frontpage'),
  109. );
  110. }
  111. /**
  112. * Executes the condition.
  113. */
  114. public function execute($node) {
  115. return $node->promote == 1;
  116. }
  117. }
  118. /**
  119. * @}
  120. */