3 namespace Drupal\views\Plugin\views\field;
5 use Drupal\views\ResultRow;
6 use Drupal\views\Plugin\views\ViewsHandlerInterface;
9 * Base field handler that has no options and renders an unformatted field.
11 interface FieldHandlerInterface extends ViewsHandlerInterface {
14 * Adds an ORDER BY clause to the query for click sort columns.
16 * @param string $order
19 public function clickSort($order);
22 * Determines if this field is click sortable.
25 * The value of 'click sortable' from the plugin definition, this defaults
28 public function clickSortable();
31 * Gets this field's label.
33 public function label();
36 * Returns an HTML element based upon the field's element type.
38 * @param bool $none_supported
39 * Whether or not this HTML element is supported.
40 * @param bool $default_empty
41 * Whether or not this HTML element is empty by default.
43 * Whether or not this HTML element is inline.
45 public function elementType($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE);
48 * Returns an HTML element for the label based upon the field's element type.
50 * @param bool $none_supported
51 * Whether or not this HTML element is supported.
52 * @param bool $default_empty
53 * Whether or not this HTML element is empty by default.
55 public function elementLabelType($none_supported = FALSE, $default_empty = FALSE);
58 * Returns an HTML element for the wrapper based upon the field's element type.
60 * @param bool $none_supported
61 * Whether or not this HTML element is supported.
62 * @param bool $default_empty
63 * Whether or not this HTML element is empty by default.
65 public function elementWrapperType($none_supported = FALSE, $default_empty = FALSE);
68 * Provides a list of elements valid for field HTML.
70 * This function can be overridden by fields that want more or fewer
71 * elements available, though this seems like it would be an incredibly
74 public function getElements();
77 * Returns the class of the field.
79 * @param bool $row_index
80 * The index of current row.
82 public function elementClasses($row_index = NULL);
85 * Replaces a value with tokens from the last field.
87 * This function actually figures out which field was last and uses its
88 * tokens so they will all be available.
90 * @param string $value
92 * @param bool $row_index
93 * The index of current row.
95 public function tokenizeValue($value, $row_index = NULL);
98 * Returns the class of the field's label.
100 * @param bool $row_index
101 * The index of current row.
103 public function elementLabelClasses($row_index = NULL);
106 * Returns the class of the field's wrapper.
108 * @param bool $row_index
109 * The index of current row.
111 public function elementWrapperClasses($row_index = NULL);
114 * Gets the entity matching the current row and relationship.
116 * @param \Drupal\views\ResultRow $values
117 * An object containing all retrieved values.
119 * @return \Drupal\Core\Entity\EntityInterface|null
120 * Returns the entity matching the values or NULL if there is no matching
123 public function getEntity(ResultRow $values);
126 * Gets the value that's supposed to be rendered.
128 * This api exists so that other modules can easy set the values of the field
129 * without having the need to change the render method as well.
131 * @param \Drupal\views\ResultRow $values
132 * An object containing all retrieved values.
133 * @param string $field
134 * Optional name of the field where the value is stored.
136 public function getValue(ResultRow $values, $field = NULL);
139 * Determines if this field will be available as an option to group the result
140 * by in the style settings.
143 * TRUE if this field handler is groupable, otherwise FALSE.
145 public function useStringGroupBy();
148 * Runs before any fields are rendered.
150 * This gives the handlers some time to set up before any handler has
153 * @param \Drupal\views\ResultRow[] $values
154 * An array of all ResultRow objects returned from the query.
156 public function preRender(&$values);
161 * @param \Drupal\views\ResultRow $values
162 * The values retrieved from a single row of a view's query result.
164 * @return string|\Drupal\Component\Render\MarkupInterface
165 * The rendered output. If the output is safe it will be wrapped in an
166 * object that implements MarkupInterface. If it is empty or unsafe it
169 public function render(ResultRow $values);
172 * Runs after every field has been rendered.
174 * This is meant to be used mainly to deal with field handlers whose output
175 * cannot be cached at row level but can be cached at display level. The
176 * typical example is the row counter. For completely uncacheable field output
177 * placeholders should be used.
179 * @param \Drupal\views\ResultRow $row
180 * An array of all ResultRow objects returned from the query.
182 * The field rendered output.
185 * An associative array of post-render token values keyed by placeholder.
187 * @see \Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait
189 public function postRender(ResultRow $row, $output);
192 * Renders a field using advanced settings.
194 * This renders a field normally, then decides if render-as-link and
195 * text-replacement rendering is necessary.
197 * @param \Drupal\views\ResultRow $values
198 * The values retrieved from a single row of a view's query result.
200 * @return string|\Drupal\Component\Render\MarkupInterface
201 * The advanced rendered output. If the output is safe it will be wrapped in
202 * an object that implements MarkupInterface. If it is empty or unsafe
203 * it will be a string.
205 public function advancedRender(ResultRow $values);
208 * Checks if a field value is empty.
212 * @param bool $empty_zero
213 * Whether or not this field is configured to consider 0 as empty.
214 * @param bool $no_skip_empty
215 * Whether or not to use empty() to check the value.
218 * TRUE if the value is considered empty, FALSE otherwise.
220 public function isValueEmpty($value, $empty_zero, $no_skip_empty = TRUE);
223 * Performs an advanced text render for the item.
225 * This is separated out as some fields may render lists, and this allows
226 * each item to be handled individually.
228 * @param array $alter
229 * The alter array of options to use.
230 * - max_length: Maximum length of the string, the rest gets truncated.
231 * - word_boundary: Trim only on a word boundary.
232 * - ellipsis: Show an ellipsis (…) at the end of the trimmed string.
233 * - html: Make sure that the html is correct.
235 * @return string|\Drupal\Component\Render\MarkupInterface
236 * The rendered output. If the output is safe it will be wrapped in an
237 * object that implements MarkupInterface. If it is empty or unsafe it
240 public function renderText($alter);
243 * Gets the 'render' tokens to use for advanced rendering.
245 * This runs through all of the fields and arguments that
246 * are available and gets their values. This will then be
247 * used in one giant str_replace().
250 * The item to render.
253 * An array of available tokens
255 public function getRenderTokens($item);
258 * Passes values to drupal_render() using $this->themeFunctions() as #theme.
260 * @param \Drupal\views\ResultRow $values
261 * Holds single row of a view's result set.
263 * @return string|\Drupal\Component\Render\MarkupInterface
264 * Returns rendered output of the given theme implementation. If the output
265 * is safe it will be wrapped in an object that implements
266 * MarkupInterface. If it is empty or unsafe it will be a string.
268 public function theme(ResultRow $values);