Commit 86beec15 authored by Matthew Radcliffe's avatar Matthew Radcliffe
Browse files

Issue #3200151: Uninstall module deletes media and media libary views

parent ea24193f
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\views_date_format_sql\Plugin;

use Drupal\Component\Plugin\Definition\PluginDefinition;

/**
 * Provides a plugin definition with no provider.
 */
class ViewsDateFormatSqlPluginDefinition extends PluginDefinition {

  /**
   * {@inheritdoc}
   */
  protected $provider = NULL;

  /**
   * Initialization method.
   *
   * @param string $id
   *   The plugin id to use.
   * @param string $class
   *   The class to use.
   */
  public function __construct($id = NULL, $class = NULL) {
    $this->id = $id;
    $this->setClass($class);
  }

}
+28 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\views_date_format_sql\Plugin;

use Drupal\Component\Plugin\DependentPluginInterface;

/**
 * Identifies views plugins to ignore provider dependency.
 *
 * Returns a component plugin with provider set to NULL so that dependencies
 * are calculated by the views plugin class instance.
 */
interface ViewsDateFormatSqlPluginInterface extends DependentPluginInterface {

  /**
   * Returns a separate plugin definition class.
   *
   * @return \Drupal\views_date_format_sql\Plugin\ViewsDateFormatSqlPluginDefinition
   *   A plugin definition class rather than the array.
   */
  public function getPluginDefinition();

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies();

}
+28 −2
Original line number Diff line number Diff line
@@ -3,8 +3,9 @@
namespace Drupal\views_date_format_sql\Plugin\views\argument;

use Drupal\views\Plugin\views\argument\NumericArgument;
use Drupal\Core\Render\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_date_format_sql\Plugin\ViewsDateFormatSqlPluginDefinition;
use Drupal\views_date_format_sql\Plugin\ViewsDateFormatSqlPluginInterface;

/**
 * An argument that filters entity timestamp field data.
@@ -13,7 +14,7 @@ use Drupal\Core\Form\FormStateInterface;
 *
 * @ViewsArgument("views_date_format_sql_argument")
 */
class ViewsDateFormatSqlArgument extends NumericArgument {
class ViewsDateFormatSqlArgument extends NumericArgument implements ViewsDateFormatSqlPluginInterface {

  private $format;
  private $format_string;
@@ -73,4 +74,29 @@ class ViewsDateFormatSqlArgument extends NumericArgument {
    ];
    $this->query->addWhere(0, $formula, $placeholders, 'formula');
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    $this->dependencies = parent::calculateDependencies();

    if ($this->options['format_date_sql']) {
      $this->dependencies['module'][] = 'views_date_format_sql';
    }

    return $this->dependencies;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition() {

    if (is_array($this->pluginDefinition)) {
      $this->pluginDefinition = new ViewsDateFormatSqlPluginDefinition($this->getPluginId(), self::class);
    }
    return $this->pluginDefinition;
  }

}
+26 −2
Original line number Diff line number Diff line
@@ -6,9 +6,10 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ResultRow;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Render\Element;
use Drupal\views_date_format_sql\Plugin\ViewsDateFormatSqlPluginDefinition;
use Drupal\views_date_format_sql\Plugin\ViewsDateFormatSqlPluginInterface;

/**
 * A field that displays entity timestamp field data. Supports grouping.
@@ -17,7 +18,7 @@ use Drupal\Core\Render\Element;
 *
 * @ViewsField("views_date_format_sql_field")
 */
class ViewsDateFormatSqlField extends EntityField {
class ViewsDateFormatSqlField extends EntityField implements ViewsDateFormatSqlPluginInterface {

  private $format;
  private $format_string;
@@ -274,4 +275,27 @@ class ViewsDateFormatSqlField extends EntityField {
    return $items;
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    $this->dependencies = parent::calculateDependencies();

    if ($this->options['format_date_sql']) {
      $this->dependencies['module'][] = 'views_date_format_sql';
    }

    return $this->dependencies;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition() {
    if (is_array($this->pluginDefinition)) {
      $this->pluginDefinition = new ViewsDateFormatSqlPluginDefinition($this->getPluginId(), self::class);
    }
    return $this->pluginDefinition;
  }

}
+15 −1
Original line number Diff line number Diff line
<?php

namespace Drupal\views_date_format_sql\Tests\Functional;
namespace Drupal\Tests\views_date_format_sql\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\views\Views;
@@ -26,6 +26,7 @@ class ViewsDateFormatSqlUninstallTest extends BrowserTestBase {
    'user',
    'views',
    'views_date_format_sql',
    'views_ui',
  ];

  /**
@@ -41,7 +42,9 @@ class ViewsDateFormatSqlUninstallTest extends BrowserTestBase {

    $privilegedUser = $this->createUser([
      'administer site configuration',
      'access media overview',
      'administer modules',
      'administer views',
      'access administration pages',
    ]);

@@ -64,7 +67,18 @@ class ViewsDateFormatSqlUninstallTest extends BrowserTestBase {
    $uninstall_edit = ['uninstall[views_date_format_sql]' => TRUE];

    $this->submitForm($uninstall_edit, 'Uninstall');
    $this->assertSession()->pageTextNotContains('Media');
    $this->submitForm([], 'Uninstall');
    $this->assertSession()->pageTextContains('The selected modules have been uninstalled.');

    // Checks if media page is accessible.
    $this->drupalGet('/admin/content/media');
    $this->assertSession()->pageTextContains('Updated');

    // Checks if view handler is working.
    // @see \Drupal\Tests\views_ui\Functional\HandlerTest::testBrokenHandlers().
    $this->drupalGet('/admin/structure/views/view/media/edit');
    $this->assertSession()->pageTextNotContains('Broken/missing handler');
  }

  /**
Loading