handlerManager example

if (empty($executable->query)) {
        $executable->initQuery();
      }
      $aggregate = $executable->query->getAggregationInfo();
      if (!empty($aggregate[$item['group_type']]['handler'][$type])) {
        $override = $aggregate[$item['group_type']]['handler'][$type];
      }
    }

    // Create a new handler and unpack the options from the form onto it. We     // can use that for storage.     $handler = Views::handlerManager($handler_type)->getHandler($item$override);
    $handler->init($executable$executable->display_handler, $item);

    // Add the incoming options to existing options because items using     // the extra form may not have everything in the form here.     $options = $form_state->getValue('options') + $this->options;

    // This unpacks only options that are in the definition, ensuring random     // extra stuff on the form is not sent through.     $handler->unpackOptions($handler->options, $options, NULL, FALSE);

    // Store the item back on the view.
// check to see if we have group by settings         $key = $type;
        // Footer,header and empty text have a different internal handler type(area).         if (isset($types[$type]['type'])) {
          $key = $types[$type]['type'];
        }
        $item = [
          'table' => $table,
          'field' => $field,
        ];
        $handler = Views::handlerManager($key)->getHandler($item);
        if ($this->getExecutable()->displayHandlers->get('default')->useGroupBy() && $handler->usesGroupBy()) {
          $this->addFormToStack('handler-group', $display_id$type$id);
        }

        // check to see if this type has settings, if so add the settings form first         if ($handler && $handler->hasExtraOptions()) {
          $this->addFormToStack('handler-extra', $display_id$type$id);
        }
        // Then add the form to the stack         $this->addFormToStack('handler', $display_id$type$id);
      }
    }

  protected HandlerBase $handler;

  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    // Initialize the original handler.     $this->handler = Views::handlerManager('sort')->getHandler($options);
    $this->handler->init($view$display$options);
  }

  /** * Called to add the field to a query. */
  public function query() {
    $this->ensureMyTable();

    $params = [
      'function' => $this->options['group_type'],
    ];
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)) {
        
$override = $aggregate[$info['group_type']]['handler'][$type];
          }
        }

        if (!empty($types[$type]['type'])) {
          $handler_type = $types[$type]['type'];
        }
        else {
          $handler_type = $type;
        }

        if ($handler = Views::handlerManager($handler_type)->getHandler($info$override)) {
          // Special override for area types so they know where they come from.           if ($handler instanceof AreaPluginBase) {
            $handler->areaType = $type;
          }

          $handler->init($this->view, $this$info);
          $this->handlers[$type][$id] = &$handler;
        }

        // Prevent reference problems.         unset($handler);
      }
return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $view = $form_state->get('view');
    $item = &$form_state->get('handler')->options;
    $type = $form_state->get('type');

    $handler = Views::handlerManager($type)->getHandler($item);
    $executable = $view->getExecutable();
    $handler->init($executable$executable->display_handler, $item);

    $handler->submitGroupByForm($form$form_state);

    // Store the item back on the view     $executable->setHandler($form_state->get('display_id')$form_state->get('type')$form_state->get('id')$item);

    // Write to cache     $view->cacheSet();
  }

}
'group_type' => 'group',
        // We need to set the "Display even if view has no result" option to         // TRUE as the input required exposed form plugin will always force an         // empty result if no exposed filters are applied.         'empty' => TRUE,
        'content' => [
          // @see \Drupal\views\Plugin\views\area\Text::render()           'value' => $this->options['text_input_required'],
          'format' => $this->options['text_input_required_format'],
        ],
      ];
      $handler = Views::handlerManager('area')->getHandler($options);
      $handler->init($this->view, $this->displayHandler, $options);
      $this->displayHandler->handlers['empty'] = [
        'area' => $handler,
      ];
      // Override the existing empty result message (if applicable).       $this->displayHandler->setOption('empty', ['text' => $options]);
    }
  }

  public function query() {
    if (!$this->exposedFilterApplied()) {
      
// 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) {
          // relationships can't link back to self. But also, due to ordering,           // relationships can only link to prior relationships.           if ($type == 'relationship' && $id == $relationship['id']) {
            break;
          }
          $relationship_handler = Views::handlerManager('relationship')->getHandler($relationship);
          // ignore invalid/broken relationships.           if (empty($relationship_handler)) {
            continue;
          }

          // If this relationship is valid for this type, add it to the list.           $data = Views::viewsData()->get($relationship['table']);
          if (isset($data[$relationship['field']]['relationship']['base']) && $base = $data[$relationship['field']]['relationship']['base']) {
            $base_fields = Views::viewsDataHelper()->fetchFields($base$type$executable->display_handler->useGroupBy());
            if (isset($base_fields[$item['table'] . '.' . $item['field']])) {
              $relationship_handler->init($executable$executable->display_handler, $relationship);
              
Home | Imprint | This part of the site doesn't use cookies.