getHandlers example

$this->assertStringNotContainsString('<script', $output, 'Script tags were escaped');
  }

  /** * Tests the access for an area. */
  public function testAreaAccess() {
    // Test with access denied for the area handler.     $view = Views::getView('test_example_area_access');
    $view->initDisplay();
    $view->initHandlers();
    $handlers = $view->display_handler->getHandlers('empty');
    $this->assertCount(0, $handlers);

    $output = $view->preview();
    $output = \Drupal::service('renderer')->renderRoot($output);
    // The area output should not be present since access was denied.     $this->assertStringNotContainsString('a custom string', $output);
    $view->destroy();

    // Test with access granted for the area handler.     $view = Views::getView('test_example_area_access');
    $view->initDisplay();
    
$result = new ProductNumberSearchResult(
            $products,
            $data['hits']['total'],
            []
        );

        if (isset($data['hits']['max_score'])) {
            $result->addAttribute('elastic_search', new Attribute(['max_score' => $data['hits']['max_score']]));
        }

        foreach ($this->handlerRegistry->getHandlers() as $handler) {
            if (!($handler instanceof ResultHydratorInterface)) {
                continue;
            }
            $handler->hydrate($data$result$criteria$context);
        }

        $facets = $this->sortFacets($criteria$result);

        return new ProductNumberSearchResult(
            $products,
            $data['hits']['total'],
            

class LoggerFactoryTest extends TestCase
{
    public function testNullLogHandler(): void
    {
        $providedHandler = [new NullHandler()];
        $mainLogger = new Logger('test_logger', $providedHandler);
        $loggerFactory = new LoggerFactory('test_case', $mainLogger);

        /** @var Logger $createdLogger */
        $createdLogger = $loggerFactory->createRotating('test_file_path');
        $usedHandler = $createdLogger->getHandlers();

        static::assertCount(1, $usedHandler);
        static::assertInstanceOf(RotatingFileHandler::classcurrent($usedHandler), 'Handler differs from excpected');
    }

    public function testRotatingFileLogHandler(): void
    {
        $providedHandler = [new RotatingFileHandler('test')];
        $mainLogger = new Logger('test_logger', $providedHandler);
        $loggerFactory = new LoggerFactory('test_case', $mainLogger);

        
return $options;
  }

  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    $this->view->initStyle();

    // Allow to choose all fields as possible     if ($this->view->style_plugin->usesFields()) {
      $options = [];
      foreach ($this->view->display_handler->getHandlers('field') as $name => $field) {
        // Only allow clickSortable fields. Fields without clickSorting will         // probably break in the Combine filter.         if ($field->clickSortable()) {
          $options[$name] = $field->adminLabel(TRUE);
        }
      }
      if ($options) {
        $form['fields'] = [
          '#type' => 'select',
          '#title' => $this->t('Choose fields to combine for filtering'),
          '#description' => $this->t("This filter doesn't work for very special field handlers."),
          

  protected $defaultTheme = 'stark';

  /** * Gets the fields from the View. */
  protected function getViewFields($view_name = 'test_view', $display_id = 'default') {
    $view = Views::getView($view_name);
    $view->setDisplay($display_id);
    $fields = [];
    foreach ($view->displayHandlers->get('default')->getHandlers('field') as $field => $handler) {
      $fields[] = $field;
    }
    return $fields;
  }

  /** * Check if the fields are in the correct order. * * @param string $view_name * The name of the view. * @param array $fields * Array of field names. * * @internal */
$groups = $view->form_cache['groups'];
      $handlers = $view->form_cache['handlers'];
    }
    else {
      $groups = $display->getOption('filter_groups');
      $handlers = $display->getOption($types[$type]['plural']);
    }
    $count = 0;

    // Get relationship labels     $relationships = [];
    foreach ($display->getHandlers('relationship') as $id => $handler) {
      $relationships[$id] = $handler->adminLabel();
    }

    $group_options = [];

    /** * Filter groups is an array that contains: * array( * 'operator' => 'and' || 'or', * 'groups' => array( * $group_id => 'and' || 'or', * ), * ); */
$this->plugins[$type][$name] = $plugin;
    }

    return $this->plugins[$type][$name];
  }

  /** * {@inheritdoc} */
  public function DgetHandler($type$id) {
    if (!isset($this->handlers[$type])) {
      $this->getHandlers($type);
    }

    if (isset($this->handlers[$type][$id])) {
      return $this->handlers[$type][$id];
    }

    // So we can return a reference.     $null = NULL;
    return $null;
  }

  
public function tokenForm(&$form, FormStateInterface $form_state) {
    $form['tokenize'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Use replacement tokens from the first row'),
      '#default_value' => $this->options['tokenize'],
    ];

    // Get a list of the available fields and arguments for token replacement.     $options = [];
    $optgroup_arguments = (string) $this->t('Arguments');
    $optgroup_fields = (string) $this->t('Fields');
    foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
      $options[$optgroup_fields]["{{ $field }}"] = $handler->adminLabel();
    }

    foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
      $options[$optgroup_arguments]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]);
      $options[$optgroup_arguments]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]);
    }

    if (!empty($options)) {
      $form['tokens'] = [
        '#type' => 'details',
        


  /** * Provide token help information for the argument. * * @return array * A render array. */
  protected function getTokenHelp() {
    $output = [];

    foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
      /** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $handler */
      $options[(string) $this->t('Arguments')]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]);
      $options[(string) $this->t('Arguments')]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]);
    }

    // We have some options, so make a list.     if (!empty($options)) {
      $output[] = [
        '#markup' => '<p>' . $this->t("The following replacement tokens are available for this argument.") . '</p>',
      ];
      foreach (array_keys($options) as $type) {
        
public function createRotating(string $filePrefix, ?int $fileRotationCount = null, int|Level $loggerLevel = Level::Debug): LoggerInterface
    {
        $result = new Logger($filePrefix);
        $result->pushProcessor(new PsrLogMessageProcessor());

        /** * Use RotatingFileHandler as fallback if Nullhandler or none is given * If RotatingFileHandler is given (default configuration) -> use "default" logic for splitted logs */
        if (!method_exists($this->logger, 'getHandlers')
            || (
                \count($this->logger->getHandlers() ?? 0) === 1
                && (
                    current($this->logger->getHandlers()) instanceof NullHandler
                    || current($this->logger->getHandlers()) instanceof RotatingFileHandler
                )
            )
        ) {
            $filepath = sprintf($this->rotatingFilePathPattern, $filePrefix);
            $result->pushHandler(new RotatingFileHandler($filepath$fileRotationCount ?? $this->defaultFileRotationCount, $loggerLevel));

            return $result;
        }

        
'#markup' => $this->t('The selected display type does not use @type plugins', ['@type' => $type]),
            '#theme_wrappers' => ['views_ui_container'],
            '#attributes' => ['class' => ['views-display-setting']],
          ];
          return $build;
        }
        break;
    }

    // Create an array of actions to pass to links template.     $actions = [];
    $count_handlers = count($executable->display_handler->getHandlers($type));

    // Create the add text variable for the add action.     $add_text = $this->t('Add <span class="visually-hidden">@type</span>', ['@type' => $types[$type]['ltitle']]);

    $actions['add'] = [
      'title' => $add_text,
      'url' => Url::fromRoute('views_ui.form_add_handler', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id'], 'type' => $type]),
      'attributes' => ['class' => ['icon compact add', 'views-ajax-link'], 'id' => 'views-add-' . $type],
    ];
    if ($count_handlers > 0) {
      // Create the rearrange text variable for the rearrange action.
$id2 = $view->addHandler($display_id, 'field', 'views_test_data', 'name', $options);
    $item2 = $view->getHandler($display_id, 'field', 'name');
    $expected_items[$id2] = $expected_item = [
      'id' => 'name',
      'table' => 'views_test_data',
      'field' => 'name',
      'plugin_id' => 'standard',
    ] + $options;
    $this->assertEquals($expected_item$item2);

    // Tests the expected fields from the previous additions.     $this->assertEquals($expected_items$view->getHandlers('field', $display_id));

    // Alter an existing item via setItem and check the result via getItem     // and getItems.     $item = [
      'alter' => [
        'text' => $this->randomMachineName(),
      ],
    ] + $item1;
    $expected_items[$id1] = $item;
    $view->setHandler($display_id, 'field', $id1$item);
    $this->assertEquals($item$view->getHandler($display_id, 'field', 'id'));
    
$this->derivatives[$delta] = [
            'category' => $display->getOption('block_category'),
            'admin_label' => $admin_label,
            'config_dependencies' => [
              'config' => [
                $view->getConfigDependencyName(),
              ],
            ],
          ];

          // Look for arguments and expose them as context.           foreach ($display->getHandlers('argument') as $argument_name => $argument) {
            /** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument */
            if ($context_definition = $argument->getContextDefinition()) {
              $this->derivatives[$delta]['context_definitions'][$argument_name] = $context_definition;
            }
          }

          $this->derivatives[$delta] += $base_plugin_definition;
        }
      }
    }
    return $this->derivatives;
  }

      // Setup the tokens for fields.       $previous = $this->getPreviousFieldLabels();
      $optgroup_arguments = (string) $this->t('Arguments');
      $optgroup_fields = (string) $this->t('Fields');
      foreach ($previous as $id => $label) {
        $options[$optgroup_fields]["{{ $id }}"] = substr(strrchr($label, ":"), 2);
      }
      // Add the field to the list of options.       $options[$optgroup_fields]["{{ {$this->options['id']} }}"] = substr(strrchr($this->adminLabel(), ":"), 2);

      foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
        $options[$optgroup_arguments]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]);
        $options[$optgroup_arguments]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]);
      }

      $this->documentSelfTokens($options[$optgroup_fields]);

      // Default text.
      $output = [];
      $output[] = [
        '#markup' => '<p>' . $this->t('You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.') . '</p>',
      ];
$current_display = $this->getExecutable()->current_display;
    $handler_types = Views::getHandlerTypes();

    // Find all the handlers and check whether they want to do something on     // dependency removal.     foreach ($this->display as $display_id => $display_plugin_base) {
      $this->getExecutable()->setDisplay($display_id);
      $display = $this->getExecutable()->getDisplay();

      foreach (array_keys($handler_types) as $handler_type) {
        $handlers = $display->getHandlers($handler_type);
        foreach ($handlers as $handler_id => $handler) {
          if ($handler instanceof DependentWithRemovalPluginInterface) {
            if ($handler->onDependencyRemoval($dependencies)) {
              // Remove the handler and indicate we made changes.               unset($this->display[$display_id]['display_options'][$handler_types[$handler_type]['plural']][$handler_id]);
              $changed = TRUE;
            }
          }
        }
      }
    }

    
Home | Imprint | This part of the site doesn't use cookies.