@@ 312-361 (lines=50) @@ | ||
309 | ]; |
|
310 | break; |
|
311 | ||
312 | case 'arguments': |
|
313 | $form['#title'] .= $this->t('Arguments'); |
|
314 | $default = $this->getOption('argument_mode'); |
|
315 | $options = [ |
|
316 | 'None' => $this->t("No special handling"), |
|
317 | 'token' => $this->t("Use tokens from the entity the view is attached to"), |
|
318 | ]; |
|
319 | ||
320 | $form['argument_mode'] = [ |
|
321 | '#type' => 'radios', |
|
322 | '#title' => $this->t("How should this display populate the view's arguments?"), |
|
323 | '#options' => $options, |
|
324 | '#default_value' => $default, |
|
325 | ]; |
|
326 | ||
327 | $form['token'] = [ |
|
328 | '#type' => 'fieldset', |
|
329 | '#title' => $this->t('Token replacement'), |
|
330 | '#collapsible' => TRUE, |
|
331 | '#states' => [ |
|
332 | 'visible' => [ |
|
333 | ':input[name=argument_mode]' => ['value' => 'token'], |
|
334 | ], |
|
335 | ], |
|
336 | ]; |
|
337 | ||
338 | $form['token']['default_argument'] = [ |
|
339 | '#title' => $this->t('Arguments'), |
|
340 | '#type' => 'textfield', |
|
341 | '#default_value' => $this->getOption('default_argument'), |
|
342 | '#description' => $this->t('You may use token replacement to provide arguments based on the current entity. Separate arguments with "/".'), |
|
343 | ]; |
|
344 | ||
345 | // Add a token browser. |
|
346 | if (\Drupal::service('module_handler')->moduleExists('token') && $entity_type = $this->getOption('entity_type')) { |
|
347 | $token_types = [$entity_type => $entity_type]; |
|
348 | $token_mapper = \Drupal::service('token.entity_mapper'); |
|
349 | if (!empty($token_types)) { |
|
350 | $token_types = array_map(function ($type) use ($token_mapper) { |
|
351 | return $token_mapper->getTokenTypeForEntityType($type); |
|
352 | }, (array) $token_types); |
|
353 | } |
|
354 | $form['token']['browser'] = [ |
|
355 | '#theme' => 'token_tree_link', |
|
356 | '#token_types' => $token_types, |
|
357 | '#global_types' => TRUE, |
|
358 | '#show_nested' => FALSE, |
|
359 | ]; |
|
360 | } |
|
361 | break; |
|
362 | ||
363 | case 'limit': |
|
364 | $form['#title'] .= $this->t('Limit'); |
|
@@ 363-412 (lines=50) @@ | ||
360 | } |
|
361 | break; |
|
362 | ||
363 | case 'limit': |
|
364 | $form['#title'] .= $this->t('Limit'); |
|
365 | $default = $this->getOption('limit_mode'); |
|
366 | $options = [ |
|
367 | 'None' => $this->t("No special handling"), |
|
368 | 'token' => $this->t("Use tokens from the entity the view is attached to"), |
|
369 | ]; |
|
370 | ||
371 | $form['limit_mode'] = [ |
|
372 | '#type' => 'radios', |
|
373 | '#title' => $this->t("How should this display populate the view's result limit?"), |
|
374 | '#options' => $options, |
|
375 | '#default_value' => $default, |
|
376 | ]; |
|
377 | ||
378 | $form['token'] = [ |
|
379 | '#type' => 'fieldset', |
|
380 | '#title' => $this->t('Token replacement'), |
|
381 | '#collapsible' => TRUE, |
|
382 | '#states' => [ |
|
383 | 'visible' => [ |
|
384 | ':input[name=limit_mode]' => ['value' => 'token'], |
|
385 | ], |
|
386 | ], |
|
387 | ]; |
|
388 | ||
389 | $form['token']['default_limit'] = [ |
|
390 | '#title' => $this->t('Limit'), |
|
391 | '#type' => 'textfield', |
|
392 | '#default_value' => $this->getOption('default_limit'), |
|
393 | '#description' => $this->t('You may use token replacement to provide the limit based on the current entity.'), |
|
394 | ]; |
|
395 | ||
396 | // Add a token browser. |
|
397 | if (\Drupal::service('module_handler')->moduleExists('token') && $entity_type = $this->getOption('entity_type')) { |
|
398 | $token_types = [$entity_type => $entity_type]; |
|
399 | $token_mapper = \Drupal::service('token.entity_mapper'); |
|
400 | if (!empty($token_types)) { |
|
401 | $token_types = array_map(function ($type) use ($token_mapper) { |
|
402 | return $token_mapper->getTokenTypeForEntityType($type); |
|
403 | }, (array) $token_types); |
|
404 | } |
|
405 | $form['token']['browser'] = [ |
|
406 | '#theme' => 'token_tree_link', |
|
407 | '#token_types' => $token_types, |
|
408 | '#global_types' => TRUE, |
|
409 | '#show_nested' => FALSE, |
|
410 | ]; |
|
411 | } |
|
412 | break; |
|
413 | } |
|
414 | } |
|
415 |