diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php b/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php index affb424..0091c71 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php @@ -7,12 +7,12 @@ namespace Drupal\content_translation\Access; -use Symfony\Component\Routing\Route; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Access\AccessCheckInterface; use Drupal\Core\Controller\ControllerInterface; +use Symfony\Component\Routing\Route; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Access check for entity translation CURD operation. diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationOverviewAccess.php b/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationOverviewAccess.php index 5663310..a8b105c 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationOverviewAccess.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationOverviewAccess.php @@ -7,12 +7,12 @@ namespace Drupal\content_translation\Access; -use Symfony\Component\Routing\Route; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Access\AccessCheckInterface; use Drupal\Core\Controller\ControllerInterface; +use Symfony\Component\Routing\Route; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Access check for entity translation overview. @@ -61,11 +61,14 @@ public function access(Route $route, Request $request) { $entity_type = $entity->entityType(); $bundle = $entity->bundle(); + // Get account details from request. + $account = $request->attributes->get('_account'); + // Get entity access callback. $definitions = $this->entityManager->getDefinitions(); $access_callback = $definitions[$entity_type]['translation']['content_translation']['access_callback']; if (call_user_func($access_callback, $entity)) { - return TRUE; + return static::ALLOW; } // Check per entity permission. @@ -73,11 +76,11 @@ public function access(Route $route, Request $request) { if ($definitions[$entity_type]['permission_granularity'] == 'bundle') { $permission = "translate {$bundle} {$entity_type}"; } - if (user_access($permission)) { - return TRUE; + if ($account->hasPermission($permission)) { + return static::ALLOW; } } - return NULL; + return static::DENY; } } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php index 6e45ccc..776f59b 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php @@ -7,12 +7,13 @@ namespace Drupal\content_translation\Controller; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Session\AccountInterface; +use Drupal\field\FieldInfo; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for entity translation controllers. @@ -34,6 +35,13 @@ class ContentTranslationController implements ControllerInterface { protected $moduleHandler; /** + * The field info service. + * + * @var \Drupal\field\FieldInfo + */ + protected $fieldInfo; + + /** * Constructs a ContentTranslationController object. * * @param \Drupal\Core\Entity\EntityManager $entity_manager @@ -41,9 +49,10 @@ class ContentTranslationController implements ControllerInterface { * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(EntityManager $entity_manager, ModuleHandlerInterface $module_handler) { + public function __construct(EntityManager $entity_manager, ModuleHandlerInterface $module_handler, FieldInfo $field_info) { $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; + $this->fieldInfo = $field_info; } /** @@ -52,7 +61,8 @@ public function __construct(EntityManager $entity_manager, ModuleHandlerInterfac public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.entity'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('field.info') ); } @@ -100,9 +110,9 @@ public function overview(EntityInterface $entity, AccountInterface $account = NU // Determine whether the current entity is translatable. $translatable = FALSE; - foreach (field_info_instances($entity_type, $entity->bundle()) as $instance) { + foreach ($this->fieldInfo->getInstances($entity_type) as $instance) { $field_name = $instance['field_name']; - $field = field_info_field($field_name); + $field = $this->fieldInfo->getField($field_name); if ($field['translatable']) { $translatable = TRUE; break; @@ -168,24 +178,8 @@ public function overview(EntityInterface $entity, AccountInterface $account = NU } $translation = $entity->translation[$langcode]; $status = !empty($translation['status']) ? t('Published') : t('Not published'); - - $status_tag = array( - '#type' => 'html_tag', - '#tag' => 'span', - '#attributes' => array( - 'class' => 'status', - 'content' => $status, - ) - ); - $status = drupal_render($status_tag); - - if (!empty($translation['outdated'])) { - $status_tag['#attributes'] = array ( - 'class' => 'marker', - 'content' => t('outdated'), - ); - $status .= drupal_render($status_tag); - } + // @todo Add a theming function here. + $status = '' . $status . '' . (!empty($translation['outdated']) ? ' ' . t('outdated') . '' : ''); if ($is_original) { $language_name = t('@language_name (Original language)', array('@language_name' => $language_name)); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php b/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php index 9ebc8b1..8f88a56 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php @@ -7,11 +7,11 @@ namespace Drupal\content_translation\Routing; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\Routing\Route; use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RoutingEvents; use Drupal\Core\Entity\EntityManager; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Routing\Route; /** * Subscriber for entity translation routes.