1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains the entity_views_handler_field_field class.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* A handler to provide proper displays for Field API fields.
|
10 |
|
|
*
|
11 |
|
|
* Overrides the default Views handler to retrieve the data from an entity via
|
12 |
|
|
* data selection.
|
13 |
|
|
*
|
14 |
|
|
* This handler may only be used in conjunction with data selection based Views
|
15 |
|
|
* tables or other base tables using a query plugin that supports data
|
16 |
|
|
* selection.
|
17 |
|
|
*
|
18 |
|
|
* @see entity_views_field_definition()
|
19 |
|
|
* @ingroup views_field_handlers
|
20 |
|
|
*/
|
21 |
|
|
class entity_views_handler_field_field extends views_handler_field_field {
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Stores the entity type of the result entities.
|
25 |
|
|
*/
|
26 |
|
|
public $entity_type;
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Stores the result entities' metadata wrappers.
|
30 |
|
|
*/
|
31 |
|
|
public $wrappers = array();
|
32 |
|
|
|
33 |
|
|
/**
|
34 |
|
|
* The entity for which this field is currently rendered.
|
35 |
|
|
*/
|
36 |
|
|
public $entity;
|
37 |
|
|
|
38 |
|
|
/**
|
39 |
|
|
* Return TRUE if the user has access to view this field.
|
40 |
|
|
*/
|
41 |
|
|
public function access() {
|
42 |
|
|
return field_access('view', $this->field_info, $this->definition['entity type']);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Overridden to add the field for the entity ID (if necessary).
|
47 |
|
|
*/
|
48 |
|
|
public function query($use_groupby = FALSE) {
|
49 |
|
|
EntityFieldHandlerHelper::query($this);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
|
|
* Adds a click-sort to the query.
|
54 |
|
|
*/
|
55 |
|
|
public function click_sort($order) {
|
56 |
|
|
EntityFieldHandlerHelper::click_sort($this, $order);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Override so it doesn't do any harm (or, anything at all).
|
61 |
|
|
*/
|
62 |
|
|
public function post_execute(&$values) { }
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Load the entities for all rows that are about to be displayed.
|
66 |
|
|
*/
|
67 |
|
|
public function pre_render(&$values) {
|
68 |
|
|
parent::pre_render($values);
|
69 |
|
|
EntityFieldHandlerHelper::pre_render($this, $values, TRUE);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Overridden to get the items our way.
|
74 |
|
|
*/
|
75 |
|
|
public function get_items($values) {
|
76 |
|
|
$items = array();
|
77 |
|
|
// Set the entity type for the parent handler.
|
78 |
|
|
$values->_field_data[$this->field_alias]['entity_type'] = $this->entity_type;
|
79 |
|
|
// We need special handling for lists of entities as the base.
|
80 |
|
|
$entities = EntityFieldHandlerHelper::get_value($this, $values, 'entity object');
|
81 |
|
|
if (!is_array($entities)) {
|
82 |
|
|
$entities = $entities ? array($entities) : array();
|
83 |
|
|
}
|
84 |
|
|
foreach ($entities as $entity) {
|
85 |
|
|
// Only try to render the field if it is even present on this bundle.
|
86 |
|
|
// Otherwise, field_view_field() will trigger a fatal.
|
87 |
|
|
list (, , $bundle) = entity_extract_ids($this->entity_type, $entity);
|
88 |
|
|
if (field_info_instance($this->entity_type, $this->definition['field_name'], $bundle)) {
|
89 |
|
|
// Set the currently rendered entity.
|
90 |
|
|
$values->_field_data[$this->field_alias]['entity'] = $entity;
|
91 |
|
|
$items = array_merge($items, $this->set_items($values, $this->view->row_index));
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
return $items;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Overridden to force displaying multiple values in a single row.
|
99 |
|
|
*/
|
100 |
|
|
function multiple_options_form(&$form, &$form_state) {
|
101 |
|
|
parent::multiple_options_form($form, $form_state);
|
102 |
|
|
$form['group_rows']['#default_value'] = TRUE;
|
103 |
|
|
$form['group_rows']['#disabled'] = TRUE;
|
104 |
|
|
}
|
105 |
|
|
} |