ui.data.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. /**
  3. * @file
  4. * Contains data type related forms.
  5. */
  6. /**
  7. * Interface for data types providing a direct input form.
  8. */
  9. interface RulesDataDirectInputFormInterface {
  10. /**
  11. * Constructs the direct input form.
  12. *
  13. * @return array
  14. * The direct input form.
  15. */
  16. public static function inputForm($name, $info, $settings, RulesPlugin $element);
  17. /**
  18. * Render the configured value.
  19. *
  20. * @return array
  21. * A renderable array.
  22. */
  23. public static function render($value);
  24. }
  25. /**
  26. * Interface for data UI classes providing an options list.
  27. */
  28. interface RulesDataInputOptionsListInterface extends RulesDataDirectInputFormInterface {
  29. /**
  30. * Returns the options list for the data type.
  31. *
  32. * For retrieving information about the used data type and parameter, the
  33. * helper RulesDataUI::getTypeInfo() may be used as following:
  34. * @code
  35. * list($type, $parameter_info) = RulesDataUI::getTypeInfo($element, $name);
  36. * @endcode
  37. *
  38. * @param RulesPlugin $element
  39. * The rules element to get the options for.
  40. * @param string $name
  41. * The name of the parameter for which to get options.
  42. *
  43. * @return array
  44. * An array of options as used by hook_options_list().
  45. */
  46. public static function optionsList(RulesPlugin $element, $name);
  47. }
  48. /**
  49. * Default UI related class for data types.
  50. */
  51. class RulesDataUI {
  52. /**
  53. * Specifies the default input mode per data type.
  54. */
  55. public static function getDefaultMode() {
  56. return 'selector';
  57. }
  58. /**
  59. * Provides the selection form for a parameter.
  60. */
  61. public static function selectionForm($name, $info, $settings, RulesPlugin $element) {
  62. if (!isset($settings[$name . ':select'])) {
  63. $settings[$name . ':select'] = '';
  64. $vars = $element->availableVariables();
  65. // Default to variables with the same name as the parameter.
  66. if (isset($vars[$name])) {
  67. $settings[$name . ':select'] = $name;
  68. }
  69. // If there is only one match, use it by default.
  70. elseif (count($matches = RulesData::matchingDataSelector($vars, $info, '', 1, FALSE)) == 1) {
  71. $settings[$name . ':select'] = rules_array_key($matches);
  72. }
  73. }
  74. $form[$name . ':select'] = array(
  75. '#type' => 'rules_data_selection',
  76. '#title' => t('Data selector'),
  77. '#default_value' => $settings[$name . ':select'],
  78. '#required' => empty($info['optional']),
  79. '#autocomplete_path' => RulesPluginUI::path($element->root()->name, 'autocomplete' . '/' . $name),
  80. // Make the autocomplete textfield big enough so that it can display
  81. // descriptions without word wraps.
  82. '#size' => 75,
  83. '#description' => t("The data selector helps you drill down into the data available to Rules. <em>To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type').</em> More useful tips about data selection is available in <a href='@url'>the online documentation</a>.",
  84. array('@url' => rules_external_help('data-selection'))),
  85. );
  86. $cache = rules_get_cache();
  87. $form['types_help'] = array(
  88. '#theme' => 'rules_settings_help',
  89. '#heading' => t('Data types'),
  90. );
  91. if ($info['type'] == '*') {
  92. $type_labels[] = t('any');
  93. }
  94. else {
  95. $types = is_array($info['type']) ? $info['type'] : array($info['type']);
  96. $type_labels = array();
  97. foreach ($types as $type) {
  98. $type_labels[] = drupal_ucfirst(isset($cache['data_info'][$type]['label']) ? $cache['data_info'][$type]['label'] : $type);
  99. }
  100. }
  101. $form['types_help']['#text'] = format_plural(count($type_labels), 'Select data of the type %types.', 'Select data of the types %types.', array('%types' => implode(', ', $type_labels)));
  102. if (!empty($info['translatable'])) {
  103. if (empty($info['custom translation language'])) {
  104. $text = t('If a multilingual data source (i.e. a translatable field) is given, the argument is translated to the current interface language.');
  105. }
  106. else {
  107. $text = t('If a multilingual data source (i.e. a translatable field) is given, the argument is translated to the configured language.');
  108. }
  109. $form['translation'] = array(
  110. '#theme' => 'rules_settings_help',
  111. '#text' => $text,
  112. '#heading' => t('Translation'),
  113. );
  114. }
  115. $form['help'] = array(
  116. '#theme' => 'rules_data_selector_help',
  117. '#variables' => $element->availableVariables(),
  118. '#parameter' => $info,
  119. );
  120. // Add data processor.
  121. $settings += array($name . ':process' => array());
  122. $form[$name . ':process'] = array();
  123. RulesDataProcessor::attachForm($form[$name . ':process'], $settings[$name . ':process'], $info, $element->availableVariables());
  124. return $form;
  125. }
  126. /**
  127. * Renders the value with a label if an options list is available.
  128. *
  129. * Used for data UI classes implementing the
  130. * RulesDataDirectInputFormInterface.
  131. *
  132. * In case an options list is available, the the usual render() method won't
  133. * be invoked, instead the selected entry is rendered via this method.
  134. *
  135. * @todo for Drupal 8: Refactor to avoid implementations have to care about
  136. * option lists when generating the form, but not when rendering values.
  137. */
  138. public static function renderOptionsLabel($value, $name, $info, RulesPlugin $element) {
  139. if (!empty($info['options list'])) {
  140. $element->call('loadBasicInclude');
  141. $options = entity_property_options_flatten(call_user_func($info['options list'], $element, $name));
  142. if (!is_array($value) && isset($options[$value])) {
  143. $value = $options[$value];
  144. }
  145. elseif (is_array($value)) {
  146. foreach ($value as $key => $single_value) {
  147. if (isset($options[$single_value])) {
  148. $value[$key] = $options[$single_value];
  149. }
  150. }
  151. $value = implode(', ', $value);
  152. }
  153. return array(
  154. 'content' => array('#markup' => check_plain($value)),
  155. '#attributes' => array('class' => array('rules-parameter-options-entry')),
  156. );
  157. }
  158. }
  159. /**
  160. * Returns the data type and parameter information for the given arguments.
  161. *
  162. * This helper may be used by options list callbacks operation at data-type
  163. * level, see RulesDataInputOptionsListInterface.
  164. */
  165. public static function getTypeInfo(RulesPlugin $element, $name) {
  166. $parameters = $element->pluginParameterInfo();
  167. return array($parameters[$name]['type'], $parameters[$name]);
  168. }
  169. }
  170. /**
  171. * UI for textual data.
  172. */
  173. class RulesDataUIText extends RulesDataUI implements RulesDataDirectInputFormInterface {
  174. /**
  175. * Overrides RulesDataUI::getDefaultMode().
  176. */
  177. public static function getDefaultMode() {
  178. return 'input';
  179. }
  180. /**
  181. * Implements RulesDataDirectInputFormInterface::inputForm().
  182. */
  183. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  184. if (!empty($info['options list'])) {
  185. // Make sure the .rules.inc of the providing module is included as the
  186. // options list callback may reside there.
  187. $element->call('loadBasicInclude');
  188. $form[$name] = array(
  189. '#type' => 'select',
  190. '#options' => call_user_func($info['options list'], $element, $name),
  191. );
  192. }
  193. else {
  194. $form[$name] = array(
  195. '#type' => 'textarea',
  196. '#rows' => 3,
  197. );
  198. RulesDataInputEvaluator::attachForm($form, $settings, $info, $element->availableVariables());
  199. }
  200. $settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
  201. $form[$name] += array(
  202. '#title' => t('Value'),
  203. '#default_value' => $settings[$name],
  204. '#required' => empty($info['optional']),
  205. '#after_build' => array('rules_ui_element_fix_empty_after_build'),
  206. );
  207. return $form;
  208. }
  209. /**
  210. * Implements RulesDataDirectInputFormInterface::render().
  211. */
  212. public static function render($value) {
  213. return array(
  214. 'content' => array('#markup' => check_plain($value)),
  215. '#attributes' => array('class' => array('rules-parameter-text')),
  216. );
  217. }
  218. }
  219. /**
  220. * UI for text tokens.
  221. */
  222. class RulesDataUITextToken extends RulesDataUIText {
  223. /**
  224. * Implements RulesDataDirectInputFormInterface::inputForm().
  225. */
  226. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  227. $form = parent::inputForm($name, $info, $settings, $element);
  228. if ($form[$name]['#type'] == 'textarea') {
  229. $form[$name]['#element_validate'][] = 'rules_ui_element_token_validate';
  230. $form[$name]['#description'] = t('May only contain lowercase letters, numbers, and underscores and has to start with a letter.');
  231. $form[$name]['#rows'] = 1;
  232. }
  233. return $form;
  234. }
  235. }
  236. /**
  237. * UI for formatted text.
  238. */
  239. class RulesDataUITextFormatted extends RulesDataUIText {
  240. /**
  241. * Implements RulesDataDirectInputFormInterface::inputForm().
  242. */
  243. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  244. $form = parent::inputForm($name, $info, $settings, $element);
  245. $settings += array($name => isset($info['default value']) ? $info['default value'] : array('value' => NULL, 'format' => NULL));
  246. $form[$name]['#type'] = 'text_format';
  247. $form[$name]['#base_type'] = 'textarea';
  248. $form[$name]['#default_value'] = $settings[$name]['value'];
  249. $form[$name]['#format'] = $settings[$name]['format'];
  250. return $form;
  251. }
  252. /**
  253. * Implements RulesDataDirectInputFormInterface::render().
  254. */
  255. public static function render($value) {
  256. return array(
  257. 'content' => array('#markup' => check_plain($value['value'])),
  258. '#attributes' => array('class' => array('rules-parameter-text-formatted')),
  259. );
  260. }
  261. }
  262. /**
  263. * UI for decimal data.
  264. */
  265. class RulesDataUIDecimal extends RulesDataUIText {
  266. /**
  267. * Implements RulesDataDirectInputFormInterface::inputForm().
  268. */
  269. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  270. $form = parent::inputForm($name, $info, $settings, $element);
  271. if (empty($info['options list'])) {
  272. $form[$name]['#type'] = 'textfield';
  273. }
  274. $form[$name]['#element_validate'][] = 'rules_ui_element_decimal_validate';
  275. $form[$name]['#rows'] = 1;
  276. return $form;
  277. }
  278. }
  279. /**
  280. * UI for integers.
  281. */
  282. class RulesDataUIInteger extends RulesDataUIText {
  283. /**
  284. * Implements RulesDataDirectInputFormInterface::inputForm().
  285. */
  286. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  287. $form = parent::inputForm($name, $info, $settings, $element);
  288. if (empty($info['options list'])) {
  289. $form[$name]['#type'] = 'textfield';
  290. }
  291. $form[$name]['#element_validate'][] = 'rules_ui_element_integer_validate';
  292. return $form;
  293. }
  294. }
  295. /**
  296. * UI for IP addresses.
  297. */
  298. class RulesDataUIIPAddress extends RulesDataUIText {
  299. /**
  300. * Implements RulesDataDirectInputFormInterface::inputForm().
  301. */
  302. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  303. $form = parent::inputForm($name, $info, $settings, $element);
  304. if (empty($info['options list'])) {
  305. $form[$name]['#type'] = 'textfield';
  306. $form[$name]['#description'] = t('If not provided, the IP address of the current user will be used.');
  307. }
  308. $form[$name]['#element_validate'][] = 'rules_ui_element_ip_address_validate';
  309. $form[$name]['#rows'] = 1;
  310. return $form;
  311. }
  312. }
  313. /**
  314. * UI for boolean data.
  315. */
  316. class RulesDataUIBoolean extends RulesDataUI implements RulesDataDirectInputFormInterface {
  317. /**
  318. * Overrides RulesDataUI::getDefaultMode().
  319. */
  320. public static function getDefaultMode() {
  321. return 'input';
  322. }
  323. /**
  324. * Implements RulesDataDirectInputFormInterface::inputForm().
  325. */
  326. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  327. $settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
  328. // Note: Due to the checkbox even optional parameter always receive a value.
  329. $form[$name] = array(
  330. '#type' => 'radios',
  331. '#default_value' => $settings[$name],
  332. '#options' => array(
  333. TRUE => t('@label: True.', array('@label' => $info['label'])),
  334. FALSE => t('@label: False.', array('@label' => $info['label'])),
  335. ),
  336. );
  337. return $form;
  338. }
  339. /**
  340. * Implements RulesDataDirectInputFormInterface::render().
  341. */
  342. public static function render($value) {
  343. return array(
  344. 'content' => array('#markup' => !empty($value) ? t('true') : t('false')),
  345. '#attributes' => array('class' => array('rules-parameter-boolean')),
  346. );
  347. }
  348. }
  349. /**
  350. * UI for dates.
  351. */
  352. class RulesDataUIDate extends RulesDataUIText {
  353. /**
  354. * Implements RulesDataDirectInputFormInterface::inputForm().
  355. */
  356. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  357. $settings += array($name => isset($info['default value']) ? $info['default value'] : (empty($info['optional']) ? gmdate('Y-m-d H:i:s', time()) : NULL));
  358. // Convert any configured timestamp into a readable format.
  359. if (is_numeric($settings[$name])) {
  360. $settings[$name] = gmdate('Y-m-d H:i:s', $settings[$name]);
  361. }
  362. $form = parent::inputForm($name, $info, $settings, $element);
  363. $form[$name]['#type'] = 'textfield';
  364. $form[$name]['#element_validate'][] = 'rules_ui_element_date_validate';
  365. // Note that the date input evaluator takes care for parsing dates using
  366. // strtotime() into a timestamp, which is the internal date format.
  367. $form[$name]['#description'] = t('The date in GMT. You may enter a fixed time (like %format) or any other values in GMT known by the PHP !strtotime function (like "+1 day"). Relative dates like "+1 day" or "now" relate to the evaluation time.',
  368. array('%format' => gmdate('Y-m-d H:i:s', time() + 86400),
  369. '!strtotime' => l('strtotime()', 'http://php.net/strtotime')));
  370. // @todo Leverage the jquery datepicker+timepicker once a module providing
  371. // The timepicker is available.
  372. return $form;
  373. }
  374. /**
  375. * Implements RulesDataDirectInputFormInterface::render().
  376. */
  377. public static function render($value) {
  378. $value = is_numeric($value) ? format_date($value, 'short') : check_plain($value);
  379. return array(
  380. 'content' => array('#markup' => $value),
  381. '#attributes' => array('class' => array('rules-parameter-date')),
  382. );
  383. }
  384. }
  385. /**
  386. * UI for duration type parameter.
  387. */
  388. class RulesDataUIDuration extends RulesDataUIText {
  389. /**
  390. * Implements RulesDataDirectInputFormInterface::inputForm().
  391. */
  392. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  393. $form = parent::inputForm($name, $info, $settings, $element);
  394. $form[$name]['#type'] = 'rules_duration';
  395. $form[$name]['#after_build'][] = 'rules_ui_element_duration_after_build';
  396. return $form;
  397. }
  398. /**
  399. * Implements RulesDataDirectInputFormInterface::render().
  400. */
  401. public static function render($value) {
  402. $value = is_numeric($value) ? format_interval($value) : check_plain($value);
  403. return array(
  404. 'content' => array('#markup' => $value),
  405. '#attributes' => array('class' => array('rules-parameter-duration')),
  406. );
  407. }
  408. }
  409. /**
  410. * UI for the URI type parameter.
  411. */
  412. class RulesDataUIURI extends RulesDataUIText {
  413. /**
  414. * Implements RulesDataDirectInputFormInterface::inputForm().
  415. */
  416. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  417. $form = parent::inputForm($name, $info, $settings, $element);
  418. $form[$name]['#rows'] = 1;
  419. $form[$name]['#description'] = t('You may enter relative URLs like %url as well as absolute URLs like %absolute-url.', array('%url' => 'user/login?destination=node', '%absolute-url' => 'https://www.drupal.org'));
  420. return $form;
  421. }
  422. }
  423. /**
  424. * UI for lists of textual data.
  425. */
  426. class RulesDataUIListText extends RulesDataUIText {
  427. /**
  428. * Overrides RulesDataUI::getDefaultMode().
  429. */
  430. public static function getDefaultMode() {
  431. return 'input';
  432. }
  433. /**
  434. * Implements RulesDataDirectInputFormInterface::inputForm().
  435. *
  436. * @todo This does not work for inputting textual values including "\n".
  437. */
  438. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  439. $settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
  440. $form = parent::inputForm($name, $info, $settings, $element);
  441. if ($form[$name]['#type'] == 'textarea') {
  442. // Fix up the value to be an array during after build.
  443. $form[$name]['#delimiter'] = "\n";
  444. $form[$name]['#after_build'][] = 'rules_ui_list_textarea_after_build';
  445. $form[$name]['#pre_render'][] = 'rules_ui_list_textarea_pre_render';
  446. $form[$name]['#default_value'] = !empty($settings[$name]) ? implode("\n", $settings[$name]) : NULL;
  447. $form[$name]['#description'] = t('A list of values, one on each line.');
  448. }
  449. else {
  450. $form[$name]['#multiple'] = TRUE;
  451. }
  452. return $form;
  453. }
  454. /**
  455. * Implements RulesDataDirectInputFormInterface::render().
  456. */
  457. public static function render($value) {
  458. return array(
  459. 'content' => array('#markup' => check_plain(implode(', ', $value))),
  460. '#attributes' => array('class' => array('rules-parameter-list')),
  461. );
  462. }
  463. }
  464. /**
  465. * UI for lists of integers.
  466. */
  467. class RulesDataUIListInteger extends RulesDataUIListText {
  468. /**
  469. * Implements RulesDataDirectInputFormInterface::inputForm().
  470. */
  471. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  472. $settings += array($name => isset($info['default value']) ? $info['default value'] : NULL);
  473. $form = parent::inputForm($name, $info, $settings, $element);
  474. if ($form[$name]['#type'] == 'textarea') {
  475. $form[$name]['#description'] = t('A list of integers, separated by commas. E.g. enter "1, 2, 3".');
  476. $form[$name]['#delimiter'] = ',';
  477. $form[$name]['#default_value'] = !empty($settings[$name]) ? implode(", ", $settings[$name]) : NULL;
  478. $form[$name]['#element_validate'][] = 'rules_ui_element_integer_list_validate';
  479. $form[$name]['#rows'] = 1;
  480. }
  481. return $form;
  482. }
  483. }
  484. /**
  485. * UI for lists of tokens.
  486. */
  487. class RulesDataUIListToken extends RulesDataUIListInteger {
  488. /**
  489. * Implements RulesDataDirectInputFormInterface::inputForm().
  490. */
  491. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  492. $form = parent::inputForm($name, $info, $settings, $element);
  493. if ($form[$name]['#type'] == 'textarea') {
  494. $form[$name]['#description'] = t('A list of text tokens, separated by commas. E.g. enter "one, two, three".');
  495. $form[$name]['#element_validate'] = array('rules_ui_element_token_list_validate');
  496. }
  497. return $form;
  498. }
  499. }
  500. /**
  501. * UI for entity-based data types.
  502. */
  503. class RulesDataUIEntity extends RulesDataUIText {
  504. /**
  505. * Overrides RulesDataUI::getDefaultMode().
  506. */
  507. public static function getDefaultMode() {
  508. return 'selector';
  509. }
  510. /**
  511. * Implements RulesDataDirectInputFormInterface::inputForm().
  512. */
  513. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  514. $form = parent::inputForm($name, $info, $settings, $element);
  515. if (empty($info['options list'])) {
  516. $form[$name]['#type'] = 'textfield';
  517. $entity_info = entity_get_info($info['type']);
  518. if (empty($entity_info['entity keys']['name'])) {
  519. $form[$name]['#element_validate'][] = 'rules_ui_element_integer_validate';
  520. }
  521. $form[$name]['#title'] = t('@entity identifier', array('@entity' => $entity_info['label']));
  522. $entity_label = strtolower($entity_info['label'][0]) . substr($entity_info['label'], 1);
  523. $form[$name]['#description'] = t('Specify an identifier of a @entity.', array('@entity' => $entity_label));
  524. }
  525. return $form;
  526. }
  527. }
  528. /**
  529. * UI for exportable entity-based data types.
  530. */
  531. class RulesDataUIEntityExportable extends RulesDataUIEntity {
  532. /**
  533. * Overrides RulesDataUI::getDefaultMode().
  534. */
  535. public static function getDefaultMode() {
  536. return 'input';
  537. }
  538. }
  539. /**
  540. * Data UI variant displaying a select list of available bundle entities.
  541. *
  542. * This is used for "bundle entities" implemented via the 'bundle of' feature
  543. * of entity.module.
  544. */
  545. class RulesDataUIBundleEntity extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
  546. /**
  547. * Overrides RulesDataUI::getDefaultMode().
  548. */
  549. public static function getDefaultMode() {
  550. return 'input';
  551. }
  552. /**
  553. * Implements RulesDataInputOptionsListInterface::optionsList().
  554. */
  555. public static function optionsList(RulesPlugin $element, $name) {
  556. list($data_type, $parameter_info) = RulesDataUI::getTypeInfo($element, $name);
  557. $bundles = array();
  558. $entity_info = entity_get_info();
  559. $bundle_of_type = $entity_info[$data_type]['bundle of'];
  560. if (isset($entity_info[$bundle_of_type]['bundles'])) {
  561. foreach ($entity_info[$bundle_of_type]['bundles'] as $bundle_name => $bundle_info) {
  562. $bundles[$bundle_name] = $bundle_info['label'];
  563. }
  564. }
  565. return $bundles;
  566. }
  567. }
  568. /**
  569. * UI for taxonomy vocabularies.
  570. *
  571. * @see RulesTaxonomyVocabularyWrapper
  572. */
  573. class RulesDataUITaxonomyVocabulary extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
  574. /**
  575. * Overrides RulesDataUI::getDefaultMode().
  576. */
  577. public static function getDefaultMode() {
  578. return 'input';
  579. }
  580. /**
  581. * Implements RulesDataInputOptionsListInterface::optionsList().
  582. */
  583. public static function optionsList(RulesPlugin $element, $name) {
  584. $options = array();
  585. foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocab) {
  586. $options[$machine_name] = $vocab->name;
  587. }
  588. return $options;
  589. }
  590. }
  591. /**
  592. * UI for lists of entity-based data types.
  593. */
  594. class RulesDataUIListEntity extends RulesDataUIListInteger {
  595. /**
  596. * Implements RulesDataDirectInputFormInterface::inputForm().
  597. */
  598. public static function inputForm($name, $info, $settings, RulesPlugin $element) {
  599. $form = parent::inputForm($name, $info, $settings, $element);
  600. if (empty($info['options list'])) {
  601. $entity_info = entity_get_info(entity_property_list_extract_type($info['type']));
  602. if (!empty($entity_info['entity keys']['name'])) {
  603. $form[$name]['#element_validate'] = array('rules_ui_element_token_list_validate');
  604. }
  605. $form[$name]['#title'] = t('@entity identifiers', array('@entity' => $entity_info['label']));
  606. $entity_label = strtolower($entity_info['label'][0]) . substr($entity_info['label'], 1);
  607. $form[$name]['#description'] = t('Specify a comma-separated list of identifiers of @entity entities.', array('@entity' => $entity_label));
  608. }
  609. return $form;
  610. }
  611. }