foldershare-8.x-1.2/src/Entity/Builder/FolderShareViewBuilder.php

src/Entity/Builder/FolderShareViewBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
 
namespace Drupal\foldershare\Entity\Builder;
 
use Drupal\Component\Utility\Html;
 
use Drupal\Core\Entity\EntityViewBuilder;
 
/**
 * Defines a builder for views of a FolderShare entity.
 *
 * This class helps to build an entity view. It supports special behavior
 * based upon the view mode:
 *
 * - 'search_index': the build is simplified to omit fields that index
 *   poorly, such as numbers, dates, views, and user interface components.
 *
 * - 'search_result': the build is simplified to omit fields that do not
 *   convey much "information scent", such as numeric IDs, views, and
 *   user interface components.
 *
 * - 'full' and other view modes: the build creates a human-readable view
 *   of the entity, including all configured fields and pseudo-fields.
 *
 * <B>Warning:</B> This class is strictly internal to the FolderShare
 * module. The class's existance, name, and content may change from
 * release to release without any promise of backwards compatability.
 *
 * @ingroup foldershare
 *
 * @see \Drupal\foldershare\Entity\FolderShare
 * @see \Drupal\foldershare\Entity\Controller\FolderShareViewController
 */
final class FolderShareViewBuilder extends EntityViewBuilder {
 
  /*---------------------------------------------------------------------
   *
   * Build.
   *
   * These functions build the indicated components of an entity view.
   *
   *---------------------------------------------------------------------*/
 
  /**
   * {@inheritdoc}
   */
  public function buildComponents(
    array &$page,
    array $entities,
    array $displays,
    $viewMode) {
    //
    // The parent class does most of the work to build a renderable array
    // with information about fields. This is primarily done as
    // a render-time callback that calls build() and then buildComponents().
    //
    // Insure there is something to build for.
    if (empty($entities) === TRUE) {
      return;
    }
 
    //
    // Adjust for search
    // -----------------
    // Search operations have two special view modes:
    // - 'search_index' = generate keywords for indexing.
    // - 'search_result' = generate content for a search result page.
    //
    // These require special handling to reduce the presentation to only
    // that appropriate for these operations.
    switch ($viewMode) {
      case 'search_index':
        // Generate keywords for a search index.
        //
        // Pseudo-fields (e.g. folder path and contents) automatically
        // skip generating content for the search view modes. We don't
        // need to handle that here.
        //
        // Loop through all of the displays and hide anything that doesn't
        // make sense when generating search index keywords.
        foreach ($displays as $display) {
          foreach ($display->getComponents() as $name => $options) {
            // Hide the field label, if it has one.
            if (isset($options['label']) === TRUE) {
              $options['label'] = 'hidden';
              $display->setComponent($name, $options);
            }
 
            // Hide well-known fields containing numeric IDs (e.g. id),
            // numeric values (e.g. size), dates (e.g. created),
            // internal keywords (e.g. kind), and internal flags (e.g.
            // systemhidden).
            switch ($name) {
              case 'id':
              case 'uid':
              case 'uuid':
              case 'parentid':
              case 'rootid':
              case 'langcode':
              case 'created':
              case 'changed':
              case 'size':
              case 'file':
              case 'kind':
              case 'grantauthoruids':
              case 'grantviewuids':
              case 'systemhidden':
              case 'systemdisabled':
                // Remove the field from display and continue on to
                // the next field.
                $display->removeComponent($name);
                continue 2;
            }
 
            // Hide pseudo-fields, which have an unset 'type'. Pseudo-fields
            // are used for a folder path and the folder contents table.
            if (empty($options['type']) === TRUE) {
              $display->removeComponent($name);
              continue;
            }
 
            // Hide fields that would be rendered as something that
            // doesn't contribute well to a search index, such as colors,
            // dates, numbers, and widgets.
            switch ($options['type']) {
              case '':
              case 'actions':
              case 'ajax':
              case 'button':
              case 'checkbox':
              case 'checkboxes':
              case 'color':
              case 'contextual_links':
              case 'contextual_links_placeholder':
              case 'date':
              case 'datelist':
              case 'datetime':
              case 'dropbutton':
              case 'entity_autocomplete':
              case 'field_ui_table':
              case 'hidden':
              case 'image_button':
              case 'inline_template':
              case 'language_configuration':
              case 'machine_name':
              case 'more_link':
              case 'number':
              case 'operations':
              case 'pager':
              case 'password':
              case 'password_confirm':
              case 'radio':
              case 'radios':
              case 'range':
              case 'responsive_image':
              case 'search':
              case 'select':
              case 'submit':
              case 'system_compact_link':
              case 'tel':
              case 'token':
              case 'toolbar':
              case 'toolbar_item':
              case 'weight':
              case 'view':
                $display->removeComponent($name);
                break;
            }
          }
        }
        break;
 
      case 'search_result':
        // Generate abbreviated output for a search result page.
        //
        // Pseudo-fields (e.g. folder path and contents) automatically
        // skip generating content for the search view modes. We don't
        // need to handle that here.
        //
        // Loop through all of the displays and hide anything that doesn't
        // make sense generating search result snippets.
        foreach ($displays as $display) {
          foreach ($display->getComponents() as $name => $options) {
            // Hide well-known fields containing numeric IDs (e.g. id),
            // numeric values (e.g. size), and internal keywords (e.g. kind).
            //
            // This is similar to, but less restrictive than the list
            // above for search indexes. For instance, this list allows
            // dates.
            switch ($name) {
              case 'id':
              case 'uid':
              case 'uuid':
              case 'parentid':
              case 'rootid':
              case 'langcode':
              case 'size':
              case 'file':
              case 'kind':
              case 'grantauthoruids':
              case 'grantviewuids':
              case 'systemhidden':
              case 'systemdisabled':
                // Remove the field from display and continue on to
                // the next field.
                $display->removeComponent($name);
                continue 2;
            }
 
            // Hide pseudo-fields, which have an unset 'type'. Pseudo-fields
            // are used for a folder path and the folder contents table.
            if (empty($options['type']) === TRUE) {
              $display->removeComponent($name);
              continue;
            }
 
            // Hide fields that would be rendered as something that
            // doesn't contribute well to a search result list, such as colors,
            // dates, numbers, and widgets.
            //
            // This list is similar to, but less restrictive than the list
            // above for search indexes. For instance, this list allows
            // dates and telephone numbers.
            switch ($options['type']) {
              case 'actions':
              case 'ajax':
              case 'button':
              case 'checkbox':
              case 'checkboxes':
              case 'color':
              case 'contextual_links':
              case 'contextual_links_placeholder':
              case 'dropbutton':
              case 'entity_autocomplete':
              case 'field_ui_table':
              case 'hidden':
              case 'image_button':
              case 'inline_template':
              case 'language_configuration':
              case 'machine_name':
              case 'more_link':
              case 'number':
              case 'operations':
              case 'pager':
              case 'password':
              case 'password_confirm':
              case 'radio':
              case 'radios':
              case 'range':
              case 'responsive_image':
              case 'search':
              case 'select':
              case 'submit':
              case 'system_compact_link':
              case 'token':
              case 'toolbar':
              case 'toolbar_item':
              case 'weight':
              case 'view':
                $display->removeComponent($name);
                break;
            }
          }
        }
        break;
    }
 
    //
    // Build defaults
    // --------------
    // Let the parent class build everything normally.
    parent::buildComponents($page, $entities, $displays, $viewMode);
 
    //
    // Additions
    // ---------
    // Add the langcode field.
    foreach ($entities as $id => $entity) {
      $display = $displays[$entity->bundle()];
      if ($display->getComponent('langcode') !== NULL) {
        $page[$id]['langcode'] = [
          '#type'   => 'item',
          '#title'  => t('Language'),
          '#markup' => Html::escape($entity->language()->getName()),
          '#prefix' => '<div id="field-language-display">',
          '#suffix' => '</div>',
        ];
      }
    }
  }
 
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc