diff --git a/crop.module b/crop.module index 0aad0d1..e313d79 100644 --- a/crop.module +++ b/crop.module @@ -29,7 +29,7 @@ function crop_theme() { */ function template_preprocess_crop_crop_summary(&$variables) { if (!empty($variables['data']['crop_type'])) { - $type = \Drupal::entityManager()->getStorage('crop_type')->load($variables['data']['crop_type']); + $type = \Drupal::entityTypeManager()->getStorage('crop_type')->load($variables['data']['crop_type']); $variables['data']['crop_type'] = $type->label(); } } @@ -44,7 +44,7 @@ function crop_form_media_bundle_form_alter(&$form, FormStateInterface $form_stat $bundle = $form['#entity']; $options = []; $allowed_field_types = ['file', 'image']; - foreach (\Drupal::entityManager()->getFieldDefinitions('media', $bundle->id()) as $field_name => $field) { + foreach (\Drupal::service('entity_field.manager')->getFieldDefinitions('media', $bundle->id()) as $field_name => $field) { if (in_array($field->getType(), $allowed_field_types) && !$field->getFieldStorageDefinition()->isBaseField()) { $options[$field_name] = $field->getLabel(); } diff --git a/modules/crop_media_entity/src/Plugin/Crop/EntityProvider/MediaEntity.php b/modules/crop_media_entity/src/Plugin/Crop/EntityProvider/MediaEntity.php index 325df20..d24c062 100644 --- a/modules/crop_media_entity/src/Plugin/Crop/EntityProvider/MediaEntity.php +++ b/modules/crop_media_entity/src/Plugin/Crop/EntityProvider/MediaEntity.php @@ -3,7 +3,7 @@ namespace Drupal\crop_media_entity\Plugin\Crop\EntityProvider; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\crop\EntityProviderBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -20,11 +20,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class MediaEntity extends EntityProviderBase implements ContainerFactoryPluginInterface { /** - * Entity manager service. + * Entity type manager service. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * Constructs media entity integration plugin. @@ -35,12 +35,12 @@ class MediaEntity extends EntityProviderBase implements ContainerFactoryPluginIn * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * Entity manager service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * Entity type manager service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->entityManager = $entity_manager; + $this->entityTypeManager = $entity_type_manager; } /** @@ -51,7 +51,7 @@ class MediaEntity extends EntityProviderBase implements ContainerFactoryPluginIn $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager') + $container->get('entity_type.manager') ); } @@ -60,7 +60,7 @@ class MediaEntity extends EntityProviderBase implements ContainerFactoryPluginIn */ public function uri(EntityInterface $entity) { /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ - $bundle = $this->entityManager->getStorage('media_bundle')->load($entity->bundle()); + $bundle = $this->entityTypeManager->getStorage('media_bundle')->load($entity->bundle()); $image_field = $bundle->getThirdPartySetting('crop', 'image_field'); if ($entity->{$image_field}->first()->isEmpty()) { @@ -68,7 +68,7 @@ class MediaEntity extends EntityProviderBase implements ContainerFactoryPluginIn } /** @var \Drupal\file\FileInterface $image */ - $image = $this->entityManager->getStorage('file')->load($entity->{$image_field}->target_id); + $image = $this->entityTypeManager->getStorage('file')->load($entity->{$image_field}->target_id); if (strpos($image->getMimeType(), 'image') !== 0) { return FALSE; diff --git a/src/CropTypeListBuilder.php b/src/CropTypeListBuilder.php index b536ba8..2e90ee8 100644 --- a/src/CropTypeListBuilder.php +++ b/src/CropTypeListBuilder.php @@ -86,7 +86,7 @@ class CropTypeListBuilder extends ConfigEntityListBuilder { public function buildRow(EntityInterface $entity) { $row = []; $row['name'] = [ - 'data' => $this->getLabel($entity), + 'data' => $entity->label(), 'class' => ['menu-label'], ]; $row['description'] = Xss::filterAdmin($entity->description); diff --git a/src/Entity/Crop.php b/src/Entity/Crop.php index c3cd4be..3f582d6 100644 --- a/src/Entity/Crop.php +++ b/src/Entity/Crop.php @@ -155,7 +155,7 @@ class Crop extends ContentEntityBase implements CropInterface { // Try to set URI if not yet defined. if (empty($this->uri->value) && !empty($this->entity_type->value) && !empty($this->entity_id->value)) { - $entity = \Drupal::entityManager()->getStorage($this->entity_type->value)->load($this->entity_id->value); + $entity = \Drupal::entityTypeManager()->getStorage($this->entity_type->value)->load($this->entity_id->value); if ($uri = $this->provider()->uri($entity)) { $this->set('uri', $uri); } diff --git a/src/Entity/CropType.php b/src/Entity/CropType.php index 763114e..a5c731b 100644 --- a/src/Entity/CropType.php +++ b/src/Entity/CropType.php @@ -131,7 +131,7 @@ class CropType extends ConfigEntityBundleBase implements \IteratorAggregate, Cro public static function getCropTypeNames() { return array_map( function ($bundle_info) { return $bundle_info['label'];}, - \Drupal::entityManager()->getBundleInfo('crop') + \Drupal::service('entity_type.bundle.info')->getBundleInfo('crop') ); } diff --git a/src/Form/CropTypeForm.php b/src/Form/CropTypeForm.php index 60ffeb0..0cb4042 100644 --- a/src/Form/CropTypeForm.php +++ b/src/Form/CropTypeForm.php @@ -4,6 +4,7 @@ namespace Drupal\crop\Form; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\crop\Plugin\Validation\Constraint\RatioValidationConstraint; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -176,7 +177,7 @@ class CropTypeForm extends EntityForm { } elseif ($status == SAVED_NEW) { drupal_set_message(t('The crop type %name has been added.', $t_args)); - $context = array_merge($t_args, array('link' => $this->l(t('View'), new Url('crop.overview_types')))); + $context = array_merge($t_args, array('link' => Link::fromTextAndUrl(t('View'), new Url('crop.overview_types')))); $this->logger('crop')->notice('Added crop type %name.', $context); } diff --git a/tests/src/Kernel/CropCRUDTest.php b/tests/src/Kernel/CropCRUDTest.php index cc2bb25..2638d8b 100644 --- a/tests/src/Kernel/CropCRUDTest.php +++ b/tests/src/Kernel/CropCRUDTest.php @@ -40,7 +40,7 @@ class CropCRUDTest extends CropUnitTestBase { $loaded = $this->container->get('config.factory')->get('crop.type.' . $values['id'])->get(); foreach ($values as $key => $value) { - $this->assertEqual($loaded[$key], $value, new FormattableMarkup('Correct value for @field found.', ['@field' => $key])); + self::assertEquals($loaded[$key], $value, new FormattableMarkup('Correct value for @field found.', ['@field' => $key])); } } @@ -91,11 +91,11 @@ class CropCRUDTest extends CropUnitTestBase { foreach ($values as $key => $value) { switch ($key) { case 'type': - $this->assertEqual($loaded_crop->{$key}->target_id, $value, new FormattableMarkup('Correct value for @field found.', ['@field' => $key])); + self::assertEquals($loaded_crop->{$key}->target_id, $value, new FormattableMarkup('Correct value for @field found.', ['@field' => $key])); break; default: - $this->assertEqual($loaded_crop->{$key}->value, $value, new FormattableMarkup('Correct value for @field found.', ['@field' => $key])); + self::assertEquals($loaded_crop->{$key}->value, $value, new FormattableMarkup('Correct value for @field found.', ['@field' => $key])); break; } } diff --git a/tests/src/Kernel/CropEntityProvidersTest.php b/tests/src/Kernel/CropEntityProvidersTest.php index c88593a..2e94c4b 100644 --- a/tests/src/Kernel/CropEntityProvidersTest.php +++ b/tests/src/Kernel/CropEntityProvidersTest.php @@ -58,7 +58,7 @@ class CropEntityProvidersTest extends CropUnitTestBase { $this->assertTrue(FALSE, 'File entity provider plugin was found.'); } - $this->assertEqual($provider->uri($file), $file->getFileUri(), 'File provider plugin returned correct URI.'); + self::assertEquals($provider->uri($file), $file->getFileUri(), 'File provider plugin returned correct URI.'); } }