Commit ce0bf882 authored by amateescu's avatar amateescu
Browse files

Clean-up usages of the deprecated entity manager service.

parent 0918c391
......@@ -9,7 +9,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Template\TwigEnvironment;
use Drupal\Core\Entity\EntityManagerInterface;
/**
* Returns responses for xmlsitemap.sitemap_xml and xmlsitemap.sitemap_xsl
......@@ -31,23 +30,15 @@ class XmlSitemapController extends ControllerBase {
*/
protected $twig;
/**
* The entity manager object.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a new XmlSitemapController object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public function __construct(StateInterface $state, TwigEnvironment $twig, EntityManagerInterface $entity_manager) {
public function __construct(StateInterface $state, TwigEnvironment $twig) {
$this->state = $state;
$this->twig = $twig;
$this->entityManager = $entity_manager;
}
/**
......@@ -55,7 +46,8 @@ class XmlSitemapController extends ControllerBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('state'), $container->get('twig'), $container->get('entity.manager')
$container->get('state'),
$container->get('twig')
);
}
......
......@@ -3,9 +3,10 @@
namespace Drupal\xmlsitemap\Form;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Entity\ContentEntityTypeInterface;
......@@ -19,11 +20,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements ContainerInjectionInterface {
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The entity type bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* {@inheritdoc}
......@@ -37,12 +45,16 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager) {
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
parent::__construct($config_factory);
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
......@@ -50,7 +62,9 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'), $container->get('entity.manager')
$container->get('config.factory'),
$container->get('entity_type.manager'),
$container->get('entity_type.bundle.info')
);
}
......@@ -66,11 +80,11 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('xmlsitemap.settings');
$entity_types = $this->entityManager->getDefinitions();
$entity_types = $this->entityTypeManager->getDefinitions();
$labels = array();
$default = array();
$anonymous_user = new AnonymousUserSession();
$bundles = $this->entityManager->getAllBundleInfo();
$bundles = $this->entityTypeBundleInfo->getAllBundleInfo();
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type instanceof ContentEntityTypeInterface) {
......@@ -169,7 +183,7 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase implements Container
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$bundles = $this->entityManager->getAllBundleInfo();
$bundles = $this->entityTypeBundleInfo->getAllBundleInfo();
$values = $form_state->getValues();
$entity_values = $values['entity_types'];
$config = $this->config('xmlsitemap.settings');
......
......@@ -3,29 +3,18 @@
namespace Drupal\xmlsitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Configure what entities will be included in sitemap.
*/
class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase implements ContainerInjectionInterface {
class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase {
private $entity_type;
private $bundle_type;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* {@inheritdoc}
*/
......@@ -33,28 +22,6 @@ class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase implements Contain
return 'xmlsitemap_link_bundle_settings_form';
}
/**
* Constructs a XmlSitemapLinkBundleSettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager) {
parent::__construct($config_factory);
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'), $container->get('entity.manager')
);
}
/**
* {@inheritdoc}
*/
......
......@@ -31,6 +31,7 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) {
parent::__construct($config_factory);
$this->state = $state;
}
......@@ -39,7 +40,8 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'), $container->get('state')
$container->get('config.factory'),
$container->get('state')
);
}
......
......@@ -34,7 +34,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
/**
* The xmlsitemap.link_storage service.
*
* @var \Drupal\xmlsitemap\XmlSitemapLinkInterface
* @var \Drupal\xmlsitemap\XmlSitemapLinkStorageInterface
*/
protected $linkStorage;
......@@ -52,6 +52,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, DateFormatter $date, XmlSitemapLinkStorageInterface $link_storage) {
parent::__construct($config_factory);
$this->state = $state;
$this->date = $date;
$this->linkStorage = $link_storage;
......@@ -62,7 +63,10 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'), $container->get('state'), $container->get('date.formatter'), $container->get('xmlsitemap.link_storage')
$container->get('config.factory'),
$container->get('state'),
$container->get('date.formatter'),
$container->get('xmlsitemap.link_storage')
);
}
......
......@@ -41,7 +41,7 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
$user_role->grantPermission('access content');
$user_role->save();
$bundles = $this->entityManager->getAllBundleInfo();
$bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
foreach ($bundles['menu_link_content'] as $bundle_id => $bundle) {
xmlsitemap_link_bundle_enable('menu_link_content', $bundle_id);
}
......@@ -89,7 +89,7 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
* {@inheritdoc}
*/
public function tearDown() {
$bundles = $this->entityManager->getAllBundleInfo();
$bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
foreach ($bundles['menu_link_content'] as $bundle_id => $bundle) {
xmlsitemap_link_bundle_delete('menu_link_content', $bundle_id);
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\xmlsitemap\Tests;
use Drupal\Core\Language\Language;
use Drupal\xmlsitemap\Entity\XmlSitemap;
/**
* Common base test class for XML sitemap internationalization tests.
......@@ -49,10 +50,10 @@ abstract class XmlSitemapMultilingualTestBase extends XmlSitemapTestBase {
$previous_sitemap->delete();
}
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
$sitemap = XmlSitemap::create();
$sitemap->context = array('language' => 'en');
xmlsitemap_sitemap_save($sitemap);
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
$sitemap = XmlSitemap::create();
$sitemap->context = array('language' => 'fr');
xmlsitemap_sitemap_save($sitemap);
}
......
......@@ -53,13 +53,6 @@ abstract class XmlSitemapTestBase extends WebTestBase {
*/
protected $moduleHandler;
/**
* The entity manager object.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The language manager object.
*
......@@ -82,7 +75,6 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$this->state = \Drupal::state();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
$this->moduleHandler = \Drupal::moduleHandler();
$this->entityManager = \Drupal::entityTypeManager();
$this->languageManager = \Drupal::languageManager();
$this->linkStorage = \Drupal::service('xmlsitemap.link_storage');
......
......@@ -5,7 +5,6 @@ namespace Drupal\xmlsitemap;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Component\Utility\Bytes;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
......@@ -47,13 +46,6 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
*/
protected $config;
/**
* The entity manager object.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* The language manager object.
*
......@@ -80,16 +72,13 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory object.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager handler.
* @param \Drupal\Core\State\StateInterface $state
* The state handler.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, StateInterface $state, LanguageManagerInterface $language_manager, LoggerInterface $logger) {
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, LanguageManagerInterface $language_manager, LoggerInterface $logger) {
$this->config = $config_factory->getEditable('xmlsitemap.settings');
$this->entityManager = $entity_manager;
$this->state = $state;
$this->languageManager = $language_manager;
$this->logger = $logger;
......
services:
xmlsitemap_generator:
class: Drupal\xmlsitemap\XmlSitemapGenerator
arguments: ['@config.factory', '@entity.manager', '@state', '@language_manager', '@logger.channel.xmlsitemap']
arguments: ['@config.factory', '@state', '@language_manager', '@logger.channel.xmlsitemap']
tags:
- { name: xmlsitemap_generator }
xmlsitemap.link_storage:
......
......@@ -68,7 +68,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$sitemaps = array();
$context = array(1);
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array(
$sitemap = XmlSitemap::create(array(
'id' => xmlsitemap_sitemap_get_context_hash($context),
));
$sitemap->setContext(serialize($context));
......@@ -81,7 +81,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$sitemaps[] = $sitemap;
$context = array(2);
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array(
$sitemap = XmlSitemap::create(array(
'id' => xmlsitemap_sitemap_get_context_hash($context),
));
$sitemap->setContext(serialize($context));
......
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