PHP code example of wieni / wmentity_overview

1. Go to this page and download the library: Download wieni/wmentity_overview library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wieni / wmentity_overview example snippets




namespace Drupal\yourmodule\Plugin\EntityOverview;

/**
 * @OverviewBuilder(
 *     entity_type = "node",
 * )
 */
class NodeOverview extends FilterableOverviewBuilderBase
{
}



namespace Drupal\yourmodule\Plugin\EntityOverview;

/**
 * @OverviewBuilder(
 *     id = "node",
 *     entity_type = "node",
 *     override = true,
 * )
 */
class NodeOverview extends FilterableOverviewBuilderBase
{
}



namespace Drupal\yourmodule\Plugin\EntityOverview;

/**
 * @OverviewBuilder(
 *     id = "redirect",
 *     entity_type = "redirect",
 *     route_name = "redirect.list",
 * )
 */
class RedirectOverview extends FilterableOverviewBuilderBase
{
}



namespace Drupal\yourmodule\Plugin\EntityOverview;

/**
 * @OverviewBuilder(
 *     id = "node.article",
 *     entity_type = "node",
 *     override = true,
 *     filters = {
 *         "type" = "article",
 *     },
 * )
 */
class ArticleOverview extends NodeOverview
{
}



use Drupal\wmentity_overview\Annotation\OverviewBuilder;

function yourmodule_entity_overview_alter(OverviewBuilder $definition, array &$overview)
{
    if (!empty($overview['form'])) {
        $overview['form']['#attributes']['class'][] = 'custom-entity-overview__form';
    }

    $overview['table']['#attributes']['class'][] = 'custom-entity-overview__table';
}



namespace Drupal\yourmodule\EventSubscriber;

use Drupal\wmentity_overview\Event\EntityOverviewAlterEvent;
use Drupal\wmentity_overview\WmEntityOverviewEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class EntityOverviewSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        $events[WmEntityOverviewEvents::ENTITY_OVERVIEW_ALTER][] = ['onAlter'];

        return $events;
    }

    public function onAlter(EntityOverviewAlterEvent $event): void
    {
        $overview = &$event->getOverview();

        if (!empty($overview['form'])) {
            $overview['form']['#attributes']['class'][] = 'custom-entity-overview__form';
        }
    
        $overview['table']['#attributes']['class'][] = 'custom-entity-overview__table';
    }
}



namespace Drupal\yourmodule\EventSubscriber;

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\wmentity_overview\Event\EntityOverviewAlternativesAlterEvent;
use Drupal\wmentity_overview\OverviewBuilder\OverviewBuilderManager;
use Drupal\wmentity_overview\WmEntityOverviewEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class EntityOverviewAlternativesSubscriber implements EventSubscriberInterface
{
    /** @var OverviewBuilderManager */
    protected $overviewBuilders;
    /** @var RouteMatchInterface */
    protected $routeMatch;

    public function __construct(
        OverviewBuilderManager $overviewBuilders,
        RouteMatchInterface $routeMatch
    ) {
        $this->overviewBuilders = $overviewBuilders;
        $this->routeMatch = $routeMatch;
    }

    public static function getSubscribedEvents()
    {
        $events[WmEntityOverviewEvents::ENTITY_OVERVIEW_ALTERNATIVES_ALTER][] = ['onTaxonomyAlternativesAlter'];

        return $events;
    }

    /**
     * Since taxonomy has a per-bundle overview, we get the bundle from
     * the route parameters and use it to add more possible alternatives.
     */
    public function onTaxonomyAlternativesAlter(EntityOverviewAlternativesAlterEvent $event): void
    {
        if (!$vocabulary = $this->routeMatch->getParameter('taxonomy_vocabulary')) {
            return;
        }

        if ($event->getDefinition()->getEntityTypeId() !== 'taxonomy_term') {
            return;
        }

        $filters = ['vid' => $vocabulary->id()];
        $alternatives = array_merge(
            $event->getAlternatives(),
            $this->overviewBuilders->getAlternativesByFilters($event->getDefinition(), $filters)
        );

        $event->setAlternatives($alternatives);
    }
}