Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds_paragraphs / src / DDSParagraphsUninstallValidator.php
Size: Mime:
<?php

namespace Drupal\dds_paragraphs;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\paragraphs\Entity\Paragraph;

/**
 * Class DDSParagraphsUninstallValidator
 * @package Drupal\dds_paragraphs
 */
class DDSParagraphsUninstallValidator implements ModuleUninstallValidatorInterface {

  /**
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $paragraphQuery;

  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->paragraphQuery = $entity_type_manager->getStorage('paragraph')->getQuery();
  }

  /**
   * {@inheritdoc}
   */
  public function validate($module) {
    $reasons = [];
    switch ($module) {
      case 'dds_paragraphs_accordion':
        $ids = $this->paragraphQuery->condition('type', ['accordion', 'accordion_item'], 'IN')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "accordion" or "accordion_item" in the database.';
        }
        break;
      case 'dds_paragraphs_appetizer':
        $ids = $this->paragraphQuery->condition('type', 'appetizer')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "appetizer" in the database.';
        }
        break;
      case 'dds_paragraphs_button':
        $ids = $this->paragraphQuery->condition('type', 'button')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "button" in the database.';
        }
        break;
      case 'dds_paragraphs_columns':
        $ids = $this->paragraphQuery->condition('type', ['full_width_column', 'one_column', 'two_column', 'three_column'], 'IN')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "full_width_column", "one_column", "two_column" or "three_column" in the database.';
        }
        break;
      case 'dds_paragraphs_flex_wrapper':
        $ids = $this->paragraphQuery->condition('type', ['flex_wrapper', 'flex_item'], 'IN')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "flex_wrapper" or "flex_item" in the database.';
        }
        break;
      case 'dds_paragraphs_global':
        $ids = \Drupal::entityQuery('paragraph')->condition('type', 'global_paragraph')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "global_paragraph" in the database.';
        }
        $ids = \Drupal::entityQuery('global_paragraph')->execute();
        if($ids) {
          $reasons[] = 'There is content entities of the type "global_paragraph" in the database.';
        }
        break;
      case 'dds_paragraphs_hero':
        $ids = $this->paragraphQuery->condition('type', 'hero')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "hero" in the database.';
        }
        break;
      case 'dds_paragraphs_image':
        $ids = $this->paragraphQuery->condition('type', 'image')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "image" in the database.';
        }
        break;
      case 'dds_paragraphs_inline_navigation':
        $ids = $this->paragraphQuery->condition('type', 'inline_navigation')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "inline_navigation" in the database.';
        }
        break;
      case 'dds_paragraphs_mailchimp':
        $ids = $this->paragraphQuery->condition('type', 'mailchimp')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "mailchimp" in the database.';
        }
        break;
      case 'dds_paragraphs_news_list':
        $ids = $this->paragraphQuery->condition('type', 'news_list')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "news_list" in the database.';
        }
        break;
      case 'dds_paragraphs_quote':
        $ids = $this->paragraphQuery->condition('type', 'quote')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "quote" in the database.';
        }
        break;
      case 'dds_paragraphs_rte':
        $ids = $this->paragraphQuery->condition('type', 'rte')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "rte" in the database.';
        }
        break;
      case 'dds_paragraphs_slideshow':
        $ids = $this->paragraphQuery->condition('type', 'slideshow')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "slideshow" in the database.';
        }
        break;
      case 'dds_paragraphs_video':
        $ids = $this->paragraphQuery->condition('type', 'video')->execute();
        if($ids) {
          $reasons[] = 'There is content for the paragraph type "video" in the database.';
        }
        break;
      default:
        break;
    }
    return $reasons;
  }


}