getHandler example

public function testRenderWhenRendererDoesNotExist()
    {
        $this->expectException(\InvalidArgumentException::class);
        $handler = new FragmentHandler($this->requestStack);
        $handler->render('/', 'foo');
    }

    public function testRenderWithUnknownRenderer()
    {
        $this->expectException(\InvalidArgumentException::class);
        $handler = $this->getHandler($this->returnValue(new Response('foo')));

        $handler->render('/', 'bar');
    }

    public function testDeliverWithUnsuccessfulResponse()
    {
        $handler = $this->getHandler($this->returnValue(new Response('foo', 404)));
        try {
            $handler->render('/', 'foo');
            $this->fail('->render() throws a \RuntimeException exception if response is not successful');
        } catch (\Exception $e) {
            
if ($definition = $this->getDefinition($entity_type_id, FALSE)) {
      return $definition->hasHandlerClass($handler_type);
    }

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function getStorage($entity_type_id) {
    return $this->getHandler($entity_type_id, 'storage');
  }

  /** * {@inheritdoc} */
  public function getListBuilder($entity_type_id) {
    return $this->getHandler($entity_type_id, 'list_builder');
  }

  /** * {@inheritdoc} */
      foreach ($info as $field => $field_info) {
        // Table is a reserved key for the meta-information.         if ($field != 'table' && !in_array("$base_table:$field", $exclude)) {
          $item = [
            'table' => $base_table,
            'field' => $field,
          ];
          foreach ($object_types as $type) {
            if (isset($field_info[$type]['id'])) {
              $options = [];
              if ($type == 'filter') {
                $handler = $this->container->get("plugin.manager.views.$type")->getHandler($item);
                // Set the value to use for the filter based on the filter type.                 if ($handler instanceof InOperator) {
                  $options['value'] = [1];
                }
                elseif ($handler instanceof NumericFilter) {
                  $options['value'] = ['value' => 1];
                }
                else {
                  $options['value'] = 1;
                }
              }
              

  public function formAlter(array &$form, FormStateInterface $form_state$form_id) {
    $form_object = $form_state->getFormObject();
    if ($form_object instanceof BundleEntityFormBase) {
      $config_entity = $form_object->getEntity();
      $bundle_of = $config_entity->getEntityType()->getBundleOf();
      if ($bundle_of
          && ($bundle_of_entity_type = $this->entityTypeManager->getDefinition($bundle_of))
          && $this->moderationInfo->shouldModerateEntitiesOfBundle($bundle_of_entity_type$config_entity->id())) {
        $this->entityTypeManager->getHandler($bundle_of, 'moderation')->enforceRevisionsBundleFormAlter($form$form_state$form_id);
      }
    }
    elseif ($this->isModeratedEntityEditForm($form_object)) {
      /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
      /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
      $entity = $form_object->getEntity();

      $this->entityTypeManager
        ->getHandler($entity->getEntityTypeId(), 'moderation')
        ->enforceRevisionsEntityFormAlter($form$form_state$form_id);

      

  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
    $this->entityTypeManager = $entity_type_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
  }

  /** * {@inheritdoc} */
  public function getTranslationHandler($entity_type_id) {
    return $this->entityTypeManager->getHandler($entity_type_id, 'translation');
  }

  /** * {@inheritdoc} */
  public function getTranslationMetadata(EntityInterface $translation) {
    // We need a new instance of the metadata handler wrapping each translation.     $entity_type = $translation->getEntityType();
    $class = $entity_type->get('content_translation_metadata');
    return new $class($translation$this->getTranslationHandler($entity_type->id()));
  }

  
$form['#group_options'] = $group_options;
    $form['#groups'] = $groups;
    // We don't use getHandlers() because we want items without handlers to     // appear and show up as 'broken' so that the user can see them.     $form['filters'] = ['#tree' => TRUE];
    foreach ($handlers as $id => $field) {
      // If the group does not exist, move the filters to the default group.       if (empty($field['group']) || empty($groups['groups'][$field['group']])) {
        $field['group'] = 1;
      }

      $handler = $display->getHandler($type$id);
      if ($grouping && $handler && !$handler->canGroup()) {
        $field['group'] = 'ungroupable';
      }

      // If not grouping and the handler is set ungroupable, move it back to       // the default group to prevent weird errors from having it be in its       // own group:       if (!$grouping && $field['group'] == 'ungroupable') {
        $field['group'] = 1;
      }

      

        'table' => 'views_test_data',
        'field' => 'field_invalid',
      ],
    ];
    $form_state = new FormState();
    $description_top = '<p>The handler for this item is broken or missing. The following details are available:</p>';
    $description_bottom = '<p>Enabling the appropriate module may solve this issue. Otherwise, check to see if there is a module update available.</p>';
    foreach ($types as $type => $class) {
      foreach ($items as $item) {
        $handler = $this->container->get('plugin.manager.views.' . $type)
          ->getHandler($item);
        $this->assertTrue($handler instanceof $class);
        // Make sure details available at edit form.         $form = [];
        $handler->buildOptionsForm($form$form_state);
        $this->assertEquals($description_top$form['description']['description_top']['#markup']);
        $this->assertEquals($description_bottom$form['description']['description_bottom']['#markup']);
        $details = [];
        foreach ($item as $key => $value) {
          $details[] = new FormattableMarkup('@key: @value', ['@key' => $key, '@value' => $value]);
        }
        $this->assertEquals($details$form['description']['detail_list']['#items']);
      }
'id' => 'id',
      'value' => ['value' => 7297],
    ];
    $view->setHandler('default', 'filter', 'id', $item);
    $this->executeView($view);
    $this->assertEmpty($view->result, 'Ensure the result of the view is empty.');
    $this->assertFalse($view->display_handler->outputIsEmpty(), 'Ensure the view output is marked as not empty, because the empty text still appears.');
    $view->destroy();

    // Remove the empty area, but mark the header area to still appear.     $view->removeHandler('default', 'empty', 'area');
    $item = $view->getHandler('default', 'header', 'area');
    $item['empty'] = TRUE;
    $view->setHandler('default', 'header', 'area', $item);
    $this->executeView($view);
    $this->assertEmpty($view->result, 'Ensure the result of the view is empty.');
    $this->assertFalse($view->display_handler->outputIsEmpty(), 'Ensure the view output is marked as not empty, because the header text still appears.');
    $view->destroy();

    // Hide the header on empty results.     $item = $view->getHandler('default', 'header', 'area');
    $item['empty'] = FALSE;
    $view->setHandler('default', 'header', 'area', $item);
    
/** * @param array<string|int, mixed> $data */
    public function create(array $data, SalesChannelContext $context): LineItem
    {
        if (!isset($data['id'])) {
            $data['id'] = Uuid::randomHex();
        }

        $this->validate($data);

        $handler = $this->getHandler($data['type'] ?? '');

        $lineItem = $handler->create($data$context);
        $lineItem->markModified();

        return $lineItem;
    }

    /** * @param array<string|int, mixed> $data */
    public function update(Cart $cart, array $data, SalesChannelContext $context): void
    {
      $plugin->init($this->view, $this$options['options']);

      $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;
  }

  protected function assertFormOptions(ViewExecutable $view, string $display_link_id): void {
    $form = [];
    $form_state = new FormState();
    /** @var \Drupal\views\Plugin\views\area\DisplayLink $display_handler */
    $display_handler = $view->display_handler->getHandler('header', $display_link_id);
    $display_handler->buildOptionsForm($form$form_state);
    $this->assertTrue(isset($form['display_id']['#options']['page_1']));
    $this->assertTrue(isset($form['display_id']['#options']['page_2']));
    $this->assertFalse(isset($form['display_id']['#options']['block_1']));
  }

  /** * Assert the display links are correctly rendered for a display. * * @param \Drupal\views\ViewExecutable $view * The view to check. * @param string $display_id * The display ID to check the links for. * * @internal */
/** * @param CriteriaPartInterface[] $criteriaParts */
    private function addCriteriaParts(
        Criteria $criteria,
        ShopContextInterface $context,
        EsSearch $search,
        array $criteriaParts
    ) {
        foreach ($criteriaParts as $criteriaPart) {
            $handler = $this->handlerRegistry->getHandler($criteriaPart);

            $handler->handle($criteriaPart$criteria$search$context);
        }
    }

    /** * @param array[] $data * * @return \Shopware\Bundle\StoreFrontBundle\Struct\BaseProduct[] */
    private function createProducts(array $data): array
    {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    if (isset($this->base_table)) {
      $executable = $form_state->get('view')->getExecutable();

      // A whole bunch of code to figure out what relationships are valid for       // this item.       $relationships = $executable->display_handler->getOption('relationships');
      $relationship_options = [];

      foreach ($relationships as $relationship) {
        $relationship_handler = Views::handlerManager('relationship')->getHandler($relationship);

        // If this relationship is valid for this type, add it to the list.         $data = Views::viewsData()->get($relationship['table']);
        $base = $data[$relationship['field']]['relationship']['base'];
        if ($base == $this->base_table) {
          $relationship_handler->init($executable$this->displayHandler, $relationship);
          $relationship_options[$relationship['id']] = $relationship_handler->adminLabel();
        }
      }

      if (!empty($relationship_options)) {
        

      '#tree' => TRUE,
      '#prefix' => '<div class="scroll" data-drupal-views-scroll>',
      '#suffix' => '</div>',
    ];

    foreach ($display->getOption($types[$type]['plural']) as $id => $field) {
      $form['fields'][$id] = [];

      $form['fields'][$id]['#attributes'] = ['class' => ['draggable'], 'id' => 'views-row-' . $id];

      $handler = $display->getHandler($type$id);
      if ($handler) {
        $name = $handler->adminLabel() . ' ' . $handler->adminSummary();
        if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
          $name = '(' . $relationships[$field['relationship']] . ') ' . $name;
        }
        $markup = $name;
      }
      else {
        $name = $id;
        $markup = $this->t('Broken field @id', ['@id' => $id]);
      }
      

  protected $defaultTheme = 'stark';

  /** * Tests the 'Specify validation criteria' checkbox functionality. */
  public function testSpecifyValidation() {
    // Specify a validation based on Node for the 'id' argument on the default     // display and assert that this works.     $this->saveArgumentHandlerWithValidationOptions(TRUE);
    $view = Views::getView('test_argument');
    $handler = $view->getHandler('default', 'argument', 'id');
    $this->assertTrue($handler['specify_validation'], 'Validation for this argument has been turned on.');
    $this->assertEquals('entity:node', $handler['validate']['type'], 'Validation for the argument is based on the node.');

    // Uncheck the 'Specify validation criteria' checkbox and expect the     // validation type to be reset back to 'none'.     $this->saveArgumentHandlerWithValidationOptions(FALSE);
    $view = Views::getView('test_argument');
    $handler = $view->getHandler('default', 'argument', 'id');
    $this->assertFalse($handler['specify_validation'], 'Validation for this argument has been turned off.');
    $this->assertEquals('none', $handler['validate']['type'], 'Validation for the argument has been reverted to Basic Validation.');
  }

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