diff --git a/entityreference.info b/entityreference.info index a231b23..561d74a 100644 --- a/entityreference.info +++ b/entityreference.info @@ -10,7 +10,12 @@ files[] = entityreference.migrate.inc ; Our plugins interfaces and abstract implementations. files[] = plugins/selection/abstract.inc +files[] = plugins/selection/views.inc files[] = plugins/behavior/abstract.inc +files[] = views/entityreference_plugin_display.inc +files[] = views/entityreference_plugin_style.inc +files[] = views/entityreference_plugin_row_fields.inc + ; Tests. files[] = tests/entityreference.handlers.test diff --git a/entityreference.module b/entityreference.module index 8b5c27b..5c98a47 100644 --- a/entityreference.module +++ b/entityreference.module @@ -465,6 +465,26 @@ function entityreference_field_property_callback(&$info, $entity_type, $field, $ } } +function entityreference_view_settings_validate($element, &$form_state, $form) { + // Split view name and display name from the 'view_and_display' value. + if (!empty($element['view_and_display']['#value'])) { + list($view, $display) = explode(':', $element['view_and_display']['#value']); + } + else { + $view = ''; + $display = ''; + } + + // Explode the 'args' string into an actual array. Beware, explode() turns an + // empty string into an array with one empty string. We'll need an empty array + // instead. + $args_string = trim($element['args']['#value']); + $args = ($args_string === '') ? array() : array_map('trim', explode(',', $args_string)); + + $value = array('view_name' => $view, 'display_name' => $display, 'args' => $args); + form_set_value($element, $value, $form_state); +} + /** * Implements hook_field_widget_info(). */ diff --git a/views/entityreference.views.inc b/views/entityreference.views.inc index 76cbc2b..2df3085 100644 --- a/views/entityreference.views.inc +++ b/views/entityreference.views.inc @@ -71,3 +71,53 @@ function entityreference_field_views_data_views_data_alter(&$data, $field) { } } } + +/** + * Implements hook_views_plugins(). + */ +function entityreference_views_plugins() { + $plugins = array( + 'display' => array( + 'entityreference' => array( + 'title' => t('Entity Reference'), + 'admin' => t('Entity Reference'), + 'help' => 'Selects referenceable entities for an entity reference field', + 'handler' => 'entityreference_plugin_display', + 'uses hook menu' => FALSE, + 'use ajax' => FALSE, + 'use pager' => FALSE, + 'accept attachments' => FALSE, + // Custom property, used with views_get_applicable_views() to retrieve + // all views with a 'Entity Reference' display. + 'entityreference display' => TRUE, + ), + ), + 'style' => array( + 'entityreference_style' => array( + 'title' => t('Entity Reference list'), + 'help' => 'Returns results as a PHP array of labels and rendered rows.', + 'handler' => 'entityreference_plugin_style', + 'theme' => 'views_view_unformatted', + 'uses row plugin' => TRUE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'entityreference', + 'even empty' => TRUE, + ), + ), + 'row' => array( + 'entityreference_fields' => array( + 'title' => t('Inline fields'), + 'help' => t('Displays the fields with an optional template.'), + 'handler' => 'entityreference_plugin_row_fields', + 'theme' => 'views_view_fields', + 'theme path' => drupal_get_path('module', 'views') . '/theme', + 'theme file' => 'theme.inc', + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'entityreference', + ), + ), + ); + return $plugins; +}