123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- class entityreference_plugin_display extends views_plugin_display {
- function option_definition() {
- $options = parent::option_definition();
-
-
- $options['style_plugin']['default'] = 'entityreference_style';
- $options['defaults']['default']['style_plugin'] = FALSE;
- $options['defaults']['default']['style_options'] = FALSE;
- $options['row_plugin']['default'] = 'entityreference_fields';
- $options['defaults']['default']['row_plugin'] = FALSE;
- $options['defaults']['default']['row_options'] = FALSE;
-
- $options['title']['default'] = '';
- $options['defaults']['default']['title'] = FALSE;
- return $options;
- }
- function get_style_type() {
- return 'entityreference';
- }
- function execute() {
- return $this->view->render($this->display->id);
- }
- function render() {
- if (!empty($this->view->result) || !empty($this->view->style_plugin->definition['even empty'])) {
- return $this->view->style_plugin->render($this->view->result);
- }
- return '';
- }
- function uses_exposed() {
- return FALSE;
- }
- function query() {
- $options = $this->get_option('entityreference_options');
-
-
-
- if (empty($options)) {
- return;
- }
-
-
- $this->id_field_alias = $id_field = $this->view->query->add_field($this->view->base_table, $this->view->base_field);
- if (strpos($id_field, '.') === FALSE) {
- $id_field = $this->view->base_table . '.' . $this->id_field_alias;
- }
-
- if (isset($options['match'])) {
- $style_options = $this->get_option('style_options');
- $value = db_like($options['match']) . '%';
- if ($options['match_operator'] != 'STARTS_WITH') {
- $value = '%' . $value;
- }
-
- $conditions = db_or();
-
- foreach ($style_options['search_fields'] as $field_alias) {
- if (!empty($field_alias)) {
-
- $field = $this->view->query->fields[$this->view->field[$field_alias]->field_alias];
-
- $conditions->condition($field['table'] . '.' . $field['field'], $value, 'LIKE');
- }
- }
- $this->view->query->add_where(NULL, $conditions);
- }
-
- if (!empty($options['ids'])) {
- $this->view->query->add_where(NULL, $id_field, $options['ids']);
- }
- $this->view->set_items_per_page($options['limit']);
- }
-
- function validate() {
- $errors = parent::validate();
-
- $style_options = $this->get_option('style_options');
- if (!isset($style_options['search_fields'])) {
- $errors[] = t('Display "@display" needs a selected search fields to work properly. See the settings for the Entity Reference list format.', array('@display' => $this->display->display_title));
- }
- else {
-
-
- $fields = array_keys($this->handlers['field']);
- foreach ($style_options['search_fields'] as $field_alias => $enabled) {
- if ($enabled && !in_array($field_alias, $fields)) {
- $errors[] = t('Display "@display" uses field %field as search field, but the field is no longer present. See the settings for the Entity Reference list format.', array('@display' => $this->display->display_title, '%field' => $field_alias));
- }
- }
- }
- return $errors;
- }
- }
|