EntityReferencePrepopulateInstanceBehavior.class.php

  1. cis7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  2. cle7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  3. ecd7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  4. elmsmedia7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  5. harmony7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  6. icor7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  7. meedjum_blog7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
  8. mooc7 sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php

Functions

Namesort descending Description
entityreference_prepopulate_providers_validate Element validate; Set the value of the providers.
theme_entityreference_prepopulate_providers_table Theme the providers table.

Classes

File

sites/all/modules/ulmus/entityreference_prepopulate/plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php
View source
  1. <?php
  2. class EntityReferencePrepopulateInstanceBehavior extends EntityReference_BehaviorHandler_Abstract {
  3. /**
  4. * Generate a settings form for this handler.
  5. */
  6. public function settingsForm($field, $instance) {
  7. $form['action'] = array(
  8. '#type' => 'select',
  9. '#title' => t('Action'),
  10. '#options' => array(
  11. 'none' => t('Do nothing'),
  12. 'hide' => t('Hide field'),
  13. 'disable' => t('Disable field'),
  14. ),
  15. '#description' => t('Action to take when prepopulating field with values via URL.'),
  16. );
  17. $form['action_on_edit'] = array(
  18. '#type' => 'checkbox',
  19. '#title' => t('Apply action on edit'),
  20. '#description' => t('Apply action when editing an existing entity.'),
  21. '#states' => array(
  22. 'invisible' => array(
  23. ':input[name="instance[settings][behaviors][prepopulate][action]"]' => array('value' => 'none'),
  24. ),
  25. ),
  26. );
  27. $form['fallback'] = array(
  28. '#type' => 'select',
  29. '#title' => t('Fallback behaviour'),
  30. '#description' => t('Determine what should happen if no values are provided via URL.'),
  31. '#options' => array(
  32. 'none' => t('Do nothing'),
  33. 'hide' => t('Hide field'),
  34. 'form_error' => t('Set form error'),
  35. 'redirect' => t('Redirect'),
  36. ),
  37. );
  38. // Get list of permissions.
  39. $perms = array();
  40. $perms[0] = t('- None -');
  41. foreach (module_list(FALSE, FALSE, TRUE) as $module) {
  42. // By keeping them keyed by module we can use optgroups with the
  43. // 'select' type.
  44. if ($permissions = module_invoke($module, 'permission')) {
  45. foreach ($permissions as $id => $permission) {
  46. $perms[$module][$id] = strip_tags($permission['title']);
  47. }
  48. }
  49. }
  50. $form['skip_perm'] = array(
  51. '#type' => 'select',
  52. '#title' => t('Skip access permission'),
  53. '#description' => t('Set a permission that will not be affected by the fallback behavior.'),
  54. '#options' => $perms,
  55. );
  56. $form['providers'] = array(
  57. '#type' => 'container',
  58. '#theme' => 'entityreference_prepopulate_providers_table',
  59. '#element_validate' => array('entityreference_prepopulate_providers_validate'),
  60. );
  61. $providers = entityreference_prepopulate_providers_info();
  62. // Sort providers by weight.
  63. $providers_names = !empty($instance['settings']['behaviors']['prepopulate']['providers']) ? array_keys($instance['settings']['behaviors']['prepopulate']['providers']) : array();
  64. $providers_names = drupal_array_merge_deep($providers_names, array_keys($providers));
  65. $weight = 0;
  66. foreach ($providers_names as $name) {
  67. $provider = $providers[$name];
  68. // Set default values.
  69. $provider += array(
  70. 'disabled' => FALSE,
  71. );
  72. $form['providers']['title'][$name] = array(
  73. '#type' => 'item',
  74. '#markup' => filter_xss($provider['title']),
  75. '#description' => filter_xss($provider['description']),
  76. );
  77. if (!isset($instance['settings']['behaviors']['prepopulate']['providers'][$name])) {
  78. // backwards compatibility with version 1.4.
  79. if ($name == 'url') {
  80. // Enable the URL provider is it is not set in the instance yet.
  81. $default_value = TRUE;
  82. }
  83. elseif ($name == 'og_context') {
  84. $default_value = !empty($instance['settings']['behaviors']['prepopulate']['og_context']);
  85. }
  86. }
  87. else {
  88. $default_value = !empty($instance['settings']['behaviors']['prepopulate']['providers'][$name]);
  89. }
  90. $form['providers']['enabled'][$name] = array(
  91. '#type' => 'checkbox',
  92. '#disabled' => $provider['disabled'],
  93. '#default_value' => $default_value,
  94. );
  95. $form['providers']['weight'][$name] = array(
  96. '#type' => 'weight',
  97. '#default_value' => $weight,
  98. '#attributes' => array('class' => array('provider-weight')),
  99. );
  100. ++$weight;
  101. }
  102. return $form;
  103. }
  104. }
  105. /**
  106. * Theme the providers table.
  107. *
  108. * @ingroup themeable
  109. */
  110. function theme_entityreference_prepopulate_providers_table($variables) {
  111. $form = $variables['form'];
  112. $provider_names = element_children($form['enabled']);
  113. foreach ($provider_names as $provider_name) {
  114. $row = array(
  115. 'data' => array(
  116. drupal_render($form['title'][$provider_name]),
  117. drupal_render($form['enabled'][$provider_name]),
  118. drupal_render($form['weight'][$provider_name]),
  119. ),
  120. 'class' => array('draggable'),
  121. );
  122. $rows[] = $row;
  123. }
  124. $header = array(
  125. array('data' => t('Provider')),
  126. array('data' => t('Enabled')),
  127. array('data' => t('Weight')),
  128. );
  129. $table_variables = array(
  130. 'header' => $header,
  131. 'rows' => $rows,
  132. 'attributes' => array('id' => 'table-providers'),
  133. );
  134. $output = theme('table', $table_variables);
  135. drupal_add_tabledrag('table-providers', 'order', 'sibling', 'provider-weight');
  136. return $output;
  137. }
  138. /**
  139. * Element validate; Set the value of the providers.
  140. */
  141. function entityreference_prepopulate_providers_validate($element, &$form_state) {
  142. $value = $form_state['values']['instance']['settings']['behaviors']['prepopulate']['providers']['enabled'];
  143. // Sort the value by the weight.
  144. uasort($value, 'drupal_sort_weight');
  145. form_set_value($element, $value, $form_state);
  146. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.