| @@ 312-363 (lines=52) @@ | ||
| 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 | '#maxlength' => 1024, |
|
| 342 | '#default_value' => $this->getOption('default_argument'), |
|
| 343 | '#description' => $this->t('You may use token replacement to provide arguments based on the current entity. Separate arguments with "/".'), |
|
| 344 | ]; |
|
| 345 | ||
| 346 | // Add a token browser. |
|
| 347 | if (\Drupal::service('module_handler')->moduleExists('token') && $entity_type = $this->getOption('entity_type')) { |
|
| 348 | $token_types = [$entity_type => $entity_type]; |
|
| 349 | $token_mapper = \Drupal::service('token.entity_mapper'); |
|
| 350 | if (!empty($token_types)) { |
|
| 351 | $token_types = array_map(function ($type) use ($token_mapper) { |
|
| 352 | return $token_mapper->getTokenTypeForEntityType($type); |
|
| 353 | }, (array) $token_types); |
|
| 354 | } |
|
| 355 | $form['token']['browser'] = [ |
|
| 356 | '#theme' => 'token_tree_link', |
|
| 357 | '#token_types' => $token_types, |
|
| 358 | '#recursion_limit' => 5, |
|
| 359 | '#global_types' => TRUE, |
|
| 360 | '#show_nested' => FALSE, |
|
| 361 | ]; |
|
| 362 | } |
|
| 363 | break; |
|
| 364 | ||
| 365 | case 'limit': |
|
| 366 | $form['#title'] .= $this->t('Limit'); |
|
| @@ 365-416 (lines=52) @@ | ||
| 362 | } |
|
| 363 | break; |
|
| 364 | ||
| 365 | case 'limit': |
|
| 366 | $form['#title'] .= $this->t('Limit'); |
|
| 367 | $default = $this->getOption('limit_mode'); |
|
| 368 | $options = [ |
|
| 369 | 'None' => $this->t("No special handling"), |
|
| 370 | 'token' => $this->t("Use tokens from the entity the view is attached to"), |
|
| 371 | ]; |
|
| 372 | ||
| 373 | $form['limit_mode'] = [ |
|
| 374 | '#type' => 'radios', |
|
| 375 | '#title' => $this->t("How should this display populate the view's result limit?"), |
|
| 376 | '#options' => $options, |
|
| 377 | '#default_value' => $default, |
|
| 378 | ]; |
|
| 379 | ||
| 380 | $form['token'] = [ |
|
| 381 | '#type' => 'fieldset', |
|
| 382 | '#title' => $this->t('Token replacement'), |
|
| 383 | '#collapsible' => TRUE, |
|
| 384 | '#states' => [ |
|
| 385 | 'visible' => [ |
|
| 386 | ':input[name=limit_mode]' => ['value' => 'token'], |
|
| 387 | ], |
|
| 388 | ], |
|
| 389 | ]; |
|
| 390 | ||
| 391 | $form['token']['default_limit'] = [ |
|
| 392 | '#title' => $this->t('Limit'), |
|
| 393 | '#type' => 'textfield', |
|
| 394 | '#maxlength' => 1024, |
|
| 395 | '#default_value' => $this->getOption('default_limit'), |
|
| 396 | '#description' => $this->t('You may use token replacement to provide the limit based on the current entity.'), |
|
| 397 | ]; |
|
| 398 | ||
| 399 | // Add a token browser. |
|
| 400 | if (\Drupal::service('module_handler')->moduleExists('token') && $entity_type = $this->getOption('entity_type')) { |
|
| 401 | $token_types = [$entity_type => $entity_type]; |
|
| 402 | $token_mapper = \Drupal::service('token.entity_mapper'); |
|
| 403 | if (!empty($token_types)) { |
|
| 404 | $token_types = array_map(function ($type) use ($token_mapper) { |
|
| 405 | return $token_mapper->getTokenTypeForEntityType($type); |
|
| 406 | }, (array) $token_types); |
|
| 407 | } |
|
| 408 | $form['token']['browser'] = [ |
|
| 409 | '#theme' => 'token_tree_link', |
|
| 410 | '#token_types' => $token_types, |
|
| 411 | '#recursion_limit' => 5, |
|
| 412 | '#global_types' => TRUE, |
|
| 413 | '#show_nested' => FALSE, |
|
| 414 | ]; |
|
| 415 | } |
|
| 416 | break; |
|
| 417 | } |
|
| 418 | } |
|
| 419 | ||