domain_views_display-1.x-dev/src/Install.php
src/Install.php
<?php
declare(strict_types=1);
namespace Drupal\domain_views_display;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\domain_views_display\Plugin\views\display_extender\DomainViewsDisplayExtender;
/**
* Handles installation tasks for the module.
*/
class Install implements ContainerInjectionInterface {
use AutowireTrait;
public function __construct(
protected readonly ConfigFactoryInterface $configFactory,
) {}
/**
* Responds to the module being installed.
*
* @param bool $is_syncing
* TRUE if the module is being installed as part of a configuration import.
*/
public function install(bool $is_syncing): void {
if ($is_syncing) {
return;
}
$config = $this->configFactory->getEditable('views.settings');
/** @var list<string> $display_extenders */
$display_extenders = $config->get('display_extenders') ?: [];
$display_extenders[] = DomainViewsDisplayExtender::ID;
$config->set('display_extenders', $display_extenders);
$config->save();
}
/**
* Responds to the module being uninstalled.
*
* @param bool $is_syncing
* TRUE if the module is being uninstalled as part of a configuration
* import.
*/
public function uninstall(bool $is_syncing): void {
if ($is_syncing) {
return;
}
$config = $this->configFactory->getEditable('views.settings');
/** @var list<string> $display_extenders */
$display_extenders = $config->get('display_extenders') ?: [];
$key = array_search(DomainViewsDisplayExtender::ID, $display_extenders);
if ($key === FALSE) {
return;
}
unset($display_extenders[$key]);
$config->set('display_extenders', $display_extenders);
$config->save();
}
}
