Commit ce1b6bed authored by Ben Stallings's avatar Ben Stallings Committed by Steven Jones
Browse files

Issue #3107955 by steven jones, benstallings, vernit, tolyan4ik: Use dependency injection

parent 25ec0d14
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
    "php": ">=8.1"
  },
  "require-dev": {
    "drupal/facets": "~3.0",
    "drupal/search_api": "~1.12",
    "drupal/xls_serialization": "~1.0"
  },
+33 −7
Original line number Diff line number Diff line
@@ -12,7 +12,9 @@ use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\Url;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\file\FileInterface;
use Drupal\rest\Plugin\views\display\RestExport;
use Drupal\search_api\Plugin\views\query\SearchApiQuery;
@@ -21,6 +23,7 @@ use Drupal\views\Views;
use Drupal\views_data_export\BatchProcessingAdapterDrupal;
use Drupal\views_data_export\BatchProcessingAdapterInterface;
use PhpOffice\PhpSpreadsheet\IOFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;

@@ -43,6 +46,31 @@ use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
 */
class DataExport extends RestExport {

  /**
   * The facet source plugin manager, if Facets module is enabled.
   *
   * @var \Drupal\facets\FacetSource\FacetSourcePluginManager|null
   */
  protected ?FacetSourcePluginManager $facetSourcePluginManager;

  /**
   * The stream wrapper manager service.
   *
   * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
   */
  protected ?StreamWrapperManagerInterface $streamWrapperManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $facetsEnabled = $container->get('module_handler')->moduleExists('facets');
    $instance->facetSourcePluginManager = $facetsEnabled ? $container->get('plugin.manager.facets.facet_source') : NULL;
    $instance->streamWrapperManager = $container->get('stream_wrapper_manager');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
@@ -250,7 +278,7 @@ class DataExport extends RestExport {
    $options['export_limit']['default'] = '0';

    // Set facet source default.
    if (\Drupal::service('module_handler')->moduleExists('facets')) {
    if ($this->facetSourcePluginManager) {
      $options['facet_settings']['default'] = 'none';
    }

@@ -337,7 +365,7 @@ class DataExport extends RestExport {
      'value' => $attach_to,
    ];

    if (\Drupal::service('module_handler')->moduleExists('facets')) {
    if ($this->facetSourcePluginManager) {
      // Add a view configuration category for data facet settings in the
      // second column.
      $categories['facet_settings'] = [
@@ -431,9 +459,8 @@ class DataExport extends RestExport {
          '#fieldset' => 'file_fieldset',
        ];

        $streamWrapperManager = \Drupal::service('stream_wrapper_manager');
        // Check if the private file system is ready to use.
        if ($streamWrapperManager->isValidScheme('private')) {
        if ($this->streamWrapperManager->isValidScheme('private')) {
          $form['store_in_public_file_directory'] = [
            '#type' => 'checkbox',
            '#title' => $this->t("Store file in public files directory"),
@@ -544,9 +571,8 @@ class DataExport extends RestExport {
          $view_module_dependencies = $dependencies['module'];
          if (in_array('search_api', $view_module_dependencies)) {
            // Check if the facets module is enabled.
            if (\Drupal::service('module_handler')->moduleExists('facets')) {
              $facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
              $facet_sources = $facet_source_plugin_manager->getDefinitions();
            if ($this->facetSourcePluginManager) {
              $facet_sources = $this->facetSourcePluginManager->getDefinitions();
              $facet_source_list = ['none' => 'None'];
              foreach ($facet_sources as $source_id => $source) {
                $facet_source_list[$source_id] = $source['label'];