Commit 25f807db authored by marcvangend's avatar marcvangend Committed by marcvangend

Issue #2513246 by tedbow, marcvangend, casey: New approach for fields as...

Issue #2513246 by tedbow, marcvangend, casey: New approach for fields as block, cleanup, documentation and coding standards
parent ccd5a872
......@@ -7,11 +7,12 @@
namespace Drupal\fieldblock;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Component\Uuid\Php;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
/**
* Class BlockEntityStorage.
......@@ -23,41 +24,51 @@ class BlockEntityStorage extends ConfigEntityStorage {
/**
* Drupal\Core\Config\ConfigFactory definition.
*
* @var \Drupal\Core\Config\ConfigFactory
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config_factory;
protected $configFactory;
/**
* Drupal\Component\Uuid\Php definition.
*
* @var \Drupal\Component\Uuid\Php
* @var \Drupal\Component\Uuid\UuidInterface
*/
protected $uuid;
protected $uuidService;
/**
* Drupal\Core\Language\LanguageManager definition.
*
* @var \Drupal\Core\Language\LanguageManager
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $language_manager;
protected $languageManager;
/**
* Drupal\Core\Entity\EntityManager definition.
*
* @var \Drupal\Core\Entity\EntityManager
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entity_manager;
protected $entityManager;
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Component\Uuid\UuidInterface $uuid_service
* The UUID service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @throws PluginNotFoundException
*/
public function __construct(ConfigFactory $config_factory, Php $uuid, LanguageManager $language_manager, EntityManager $entity_manager) {
$this->config_factory = $config_factory;
$this->uuid = $uuid;
$this->language_manager = $language_manager;
$this->entity_manager = $entity_manager;
public function __construct(ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager) {
$this->configFactory = $config_factory;
$this->uuidService = $uuid_service;
$this->languageManager = $language_manager;
$this->entityManager = $entity_manager;
$entity_type = $entity_manager->getDefinition('block');
parent::__construct($entity_type, $config_factory, $uuid, $language_manager);
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
}
/**
......@@ -80,8 +91,6 @@ class BlockEntityStorage extends ConfigEntityStorage {
* @return array
*/
public function getEntityTypesUsed() {
/** @var BlockEntityStorage $block_storage */
$blocks = $this->loadFieldBlocks();
$entity_types = [];
/** @var \Drupal\block\Entity\Block $block */
......
......@@ -7,13 +7,13 @@
namespace Drupal\fieldblock\Form;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\fieldblock\Controller\FieldBlockController;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\fieldblock\BlockEntityStorage;
/**
......@@ -22,9 +22,9 @@ use Drupal\fieldblock\BlockEntityStorage;
class FieldBlockConfigForm extends ConfigFormBase {
/**
* Drupal\Core\Entity\EntityManager definition.
* Drupal\Core\Entity\EntityManagerInterface definition.
*
* @var \Drupal\Core\Entity\EntityManager
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
......@@ -42,10 +42,10 @@ class FieldBlockConfigForm extends ConfigFormBase {
* Constructs a \Drupal\fieldblock\Form\FieldBlockConfigForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* @param \Drupal\fieldblock\BlockEntityStorage $storage
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManager $entity_manager, BlockEntityStorage $storage) {
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, BlockEntityStorage $storage) {
parent::__construct($config_factory);
$this->entityManager = $entity_manager;
$this->storage = $storage;
......@@ -91,11 +91,11 @@ class FieldBlockConfigForm extends ConfigFormBase {
);
$orphaned_types = $this->getOrphanedEntityTypes($enabled);
$cleanup_options = [];
$entity_type_defs = $this->entityManager->getDefinitions();
$entity_type_definitions = $this->entityManager->getDefinitions();
foreach ($orphaned_types as $entity_type) {
if (isset($entity_type_defs[$entity_type])) {
// This entity type still exists on the site
$cleanup_options[$entity_type] = $entity_type_defs[$entity_type]->getLabel();
if (isset($entity_type_definitions[$entity_type]) && $entity_type_definitions[$entity_type] instanceof ContentEntityTypeInterface) {
// This entity type still exists on the site.
$cleanup_options[$entity_type] = $entity_type_definitions[$entity_type]->getLabel();
}
else {
// This entity type no longer exists on the site.
......@@ -196,8 +196,12 @@ class FieldBlockConfigForm extends ConfigFormBase {
* Get all entity types that have Field Blocks but are either:
* 1. No longer set to be used with this module
* 2. Don't exist on the site.
* @return array
* Entity type ids.
*
* @param array $enabled_entity_types
* Currently enabled entity types.
* @return array Entity type ids.
* Entity type ids.
* @todo param and return doc blocks must specify array of what, eg. string[].
*/
protected function getOrphanedEntityTypes($enabled_entity_types) {
$orphaned_types = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment