Skip to content

Commit

Permalink
PHPCS issue fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Feb 23, 2023
1 parent 505ef3b commit 14813c4
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\jwt\Authentication\Provider\JwtAuth;
use Drupal\next\Annotation\PreviewUrlGenerator;
use Drupal\next\Entity\NextSiteInterface;
use Drupal\next\Exception\InvalidPreviewUrlRequest;
use Drupal\next\Plugin\ConfigurablePreviewUrlGeneratorBase;
Expand Down
1 change: 0 additions & 1 deletion modules/next/next.install
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function next_update_9103() {
}
}


/**
* Add the revalidator, revalidate_page and revalidate_paths to next_entity_type_config.
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/next/src/Controller/NextSiteEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function environmentVariables(NextSiteInterface $next_site) {
'#context' => [
'name' => $name,
'value' => $value,
]
],
];
}

Expand Down
152 changes: 77 additions & 75 deletions modules/next/src/Controller/SitePreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Drupal\next\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\node\Entity\Node;
use Drupal\next\NextEntityTypeManager;
use Drupal\next\Plugin\SitePreviewerManagerInterface;
use Drupal\node\Entity\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -16,84 +16,86 @@
* removed at any time without warning. External code should not extend or
* use this class in any way!
*/
class SitePreviewController extends ControllerBase
{
/**
* The next entity type manager.
*
* @var \Drupal\next\NextEntityTypeManager
*/
protected $nextEntityTypeManager;

/**
* The site previewer manager.
*
* @var \Drupal\next\Plugin\SitePreviewerManagerInterface
*/
protected $sitePreviewerManager;

public function __construct(NextEntityTypeManager $nextEntityTypeManager, SitePreviewerManagerInterface $sitePreviewerManager)
{
$this->nextEntityTypeManager = $nextEntityTypeManager;
$this->sitePreviewerManager = $sitePreviewerManager;
}
class SitePreviewController extends ControllerBase {
/**
* The next entity type manager.
*
* @var \Drupal\next\NextEntityTypeManager
*/
protected $nextEntityTypeManager;

/**
* The site previewer manager.
*
* @var \Drupal\next\Plugin\SitePreviewerManagerInterface
*/
protected $sitePreviewerManager;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container)
{
return new static(
$container->get('next.entity_type.manager'),
$container->get('plugin.manager.next.site_previewer')
/**
*
*/
public function __construct(NextEntityTypeManager $nextEntityTypeManager, SitePreviewerManagerInterface $sitePreviewerManager) {
$this->nextEntityTypeManager = $nextEntityTypeManager;
$this->sitePreviewerManager = $sitePreviewerManager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('next.entity_type.manager'),
$container->get('plugin.manager.next.site_previewer')
);
}
}

/**
* Displays the node title for preview.
*
* @param \Drupal\node\Entity\Node $node
* [description].
*
* @return string [description].
*/
public function nodePreviewTitle(Node $node) {
return 'Preview: ' . $node->getTitle();
}

/**
* Displays the node title for preview.
* @param Node $node [description]
* @return string [description]
*/
public function nodePreviewTitle(Node $node)
{
return 'Preview: ' . $node->getTitle();
/**
* Displays the next.js site preview of a node.
*/
public function nodePreview(Node $node) {
$storage = \Drupal::entityTypeManager()->getStorage($node->getEntityTypeId());
$revision = $storage->loadRevision($storage->getLatestRevisionId($node->id()));

$next_entity_type_config = $this->nextEntityTypeManager->getConfigForEntityType($revision->getEntityTypeId(), $revision->bundle());
$sites = $next_entity_type_config->getSiteResolver()->getSitesForEntity($revision);
if (!count($sites)) {
throw new \Exception('Next.js sites for the entity could not be resolved.');
}

/**
* Displays the next.js site preview of a node.
*/
public function nodePreview(Node $node)
{
$storage = \Drupal::entityTypeManager()->getStorage($node->getEntityTypeId());
$revision = $storage->loadRevision($storage->getLatestRevisionId($node->id()));

$next_entity_type_config = $this->nextEntityTypeManager->getConfigForEntityType($revision->getEntityTypeId(), $revision->bundle());
$sites = $next_entity_type_config->getSiteResolver()->getSitesForEntity($revision);
if (!count($sites)) {
throw new \Exception('Next.js sites for the entity could not be resolved.');
}

$config = $this->config('next.settings');
$site_previewer_id = $config->get('site_previewer') ?? 'iframe';

/** @var \Drupal\next\Plugin\SitePreviewerInterface $site_previewer */
$site_previewer = $this->sitePreviewerManager->createInstance($site_previewer_id, $config->get('site_previewer_configuration') ?? []);
if (!$site_previewer) {
throw new PluginNotFoundException('Invalid site previewer.');
}

// Build preview.
$preview = $site_previewer->render($revision, $sites);

$context = [
'plugin' => $site_previewer,
'entity' => $revision,
'sites' => $sites,
];

// Allow modules to alter the preview.
$this->moduleHandler()->alter('next_site_preview', $preview, $context);

return $preview;
$config = $this->config('next.settings');
$site_previewer_id = $config->get('site_previewer') ?? 'iframe';

/** @var \Drupal\next\Plugin\SitePreviewerInterface $site_previewer */
$site_previewer = $this->sitePreviewerManager->createInstance($site_previewer_id, $config->get('site_previewer_configuration') ?? []);
if (!$site_previewer) {
throw new PluginNotFoundException('Invalid site previewer.');
}

// Build preview.
$preview = $site_previewer->render($revision, $sites);

$context = [
'plugin' => $site_previewer,
'entity' => $revision,
'sites' => $sites,
];

// Allow modules to alter the preview.
$this->moduleHandler()->alter('next_site_preview', $preview, $context);

return $preview;
}

}
1 change: 0 additions & 1 deletion modules/next/src/Entity/NextEntityTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\next\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\next\Plugin\RevalidatorInterface;
use Drupal\next\Plugin\SiteResolverInterface;
use Drupal\next\RevalidatorPluginCollection;
Expand Down
3 changes: 0 additions & 3 deletions modules/next/src/Entity/NextEntityTypeConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace Drupal\next\Entity;

use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\next\Plugin\RevalidatorInterface;
use Drupal\next\Plugin\SiteResolverInterface;
use Drupal\next\RevalidatorPluginCollection;
use Drupal\next\SiteResolverPluginCollection;

/**
* Provides an interface for next_entity_type_config entity definitions.
Expand Down
2 changes: 1 addition & 1 deletion modules/next/src/Entity/NextSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function getPreviewUrlForEntity(EntityInterface $entity): Url {
$resource_version = $rel ? "rel:$rel" : "id:{$entity->getRevisionId()}";
}

// TODO: Extract this to a service.
// @todo Extract this to a service.
/** @var \Drupal\next\NextSettingsManagerInterface $next_settings */
$next_settings = \Drupal::service('next.settings.manager');
$preview_url_generator = $next_settings->getPreviewUrlGenerator();
Expand Down
2 changes: 0 additions & 2 deletions modules/next/src/Event/EntityRevalidatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\next\Event;

use Drupal\Core\Entity\EntityInterface;

/**
* Defines an entity revalidated event.
*
Expand Down
4 changes: 2 additions & 2 deletions modules/next/src/Form/NextSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
use Drupal\next\Plugin\ConfigurableSitePreviewerInterface;
use Drupal\next\Plugin\ConfigurablePreviewUrlGeneratorInterface;
use Drupal\next\Plugin\SitePreviewerManagerInterface;
use Drupal\next\Plugin\ConfigurableSitePreviewerInterface;
use Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface;
use Drupal\next\Plugin\SitePreviewerManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down
4 changes: 2 additions & 2 deletions modules/next/src/NextEntityTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getConfigEntityTypeIds() {
public function getEntityFromRouteMatch(RouteMatchInterface $route_match): ?EntityInterface {
$entity_types_ids = $this->getConfigEntityTypeIds();

// TODO: Handle all revisionable entity types.
// @todo Handle all revisionable entity types.
$revision_routes = ['entity.node.revision', 'entity.node.latest_version'];
if (in_array($route_match->getRouteName(), $revision_routes) && in_array('node', $entity_types_ids)) {
$node_revision = $route_match->getParameter('node_revision');
Expand Down Expand Up @@ -94,7 +94,7 @@ public function getEntityFromRouteMatch(RouteMatchInterface $route_match): ?Enti
*/
public function isEntityRevisionable(EntityInterface $entity): bool {
if (\Drupal::hasService('jsonapi.resource_type.repository')) {
/* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository */
/** @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository */
$resource_type_repository = \Drupal::service('jsonapi.resource_type.repository');
$resource = $resource_type_repository->get($entity->getEntityTypeId(), $entity->bundle());
return $resource->isVersionable() && $entity->getEntityType()->isRevisionable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\next\Annotation\PreviewUrlGenerator;
use Drupal\next\Entity\NextSiteInterface;
use Drupal\next\Exception\InvalidPreviewUrlRequest;
use Drupal\next\Plugin\ConfigurablePreviewUrlGeneratorBase;
Expand Down
1 change: 0 additions & 1 deletion modules/next/src/Plugin/Next/Revalidator/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\next\Plugin\Next\Revalidator;

use Drupal\Core\Form\FormStateInterface;
use Drupal\next\Annotation\Revalidator;
use Drupal\next\Event\EntityActionEvent;
use Drupal\next\Plugin\ConfigurableRevalidatorBase;
use Drupal\next\Plugin\RevalidatorInterface;
Expand Down
7 changes: 3 additions & 4 deletions modules/next/src/Plugin/Next/SitePreviewer/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\next\Form\IframeSitePreviewerSwitcherForm;
use Drupal\next\Plugin\ConfigurableSitePreviewerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -191,7 +190,7 @@ public function render(EntityInterface $entity, array $sites) {
'class' => [
$entity->isPublished() ? 'published' : '',
],
]
],
];
}

Expand Down Expand Up @@ -243,8 +242,8 @@ public function render(EntityInterface $entity, array $sites) {
'iframe_preview' => [
'sync_route' => $this->configuration['sync_route'],
'skip_routes' => array_map('trim', explode("\n", mb_strtolower($this->configuration['sync_route_skip_routes']))),
]
]
],
],
],
'library' => [
'next/site_preview.iframe',
Expand Down
1 change: 0 additions & 1 deletion modules/next/src/Plugin/RevalidatorBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\next\NextSettingsManagerInterface;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down
1 change: 0 additions & 1 deletion modules/next/src/Plugin/RevalidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\next\Plugin;

use Drupal\Core\Entity\EntityInterface;
use Drupal\next\Event\EntityActionEvent;

/**
Expand Down
1 change: 0 additions & 1 deletion modules/next/src/Plugin/SitePreviewerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\next\Annotation\SitePreviewer;
use Drupal\next\Annotation\SiteResolver;

/**
* Plugin manager for site previewers.
Expand Down
4 changes: 2 additions & 2 deletions modules/next/src/Render/MainContent/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte
return $build;
}

// TODO: Make this configurable?
// @todo Make this configurable?
$entity_type_id = $entity->getEntityTypeId();
$revision_routes = $entity->getEntityType()->isRevisionable() ? [
"entity.$entity_type_id.revision",
"entity.$entity_type_id.latest_version"
"entity.$entity_type_id.latest_version",
] : [];
$routes = array_merge(["entity.$entity_type_id.canonical"], $revision_routes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function setUp(): void {
'id' => 'blog',
'base_url' => 'https://blog.com',
'preview_url' => 'https://blog.com/api/preview',
'preview_secret' => 'one'
'preview_secret' => 'one',
]);
$this->nextSite->save();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testEnvironmentVariables() {
*/
public function testOverriddenEnvironmentVariables() {
$GLOBALS['config']['next.next_site.' . $this->nextSite->id()] = [
'preview_secret' => 'overridden'
'preview_secret' => 'overridden',
];
$overridden_entity = NextSite::load($this->nextSite->id());
$controller = NextSiteEntityController::create($this->container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function setUp(): void {
*/
public function testSiteResolver() {
$blog_site = NextSite::create([
'id' => 'blog'
'id' => 'blog',
]);
$blog_site->save();

Expand Down Expand Up @@ -116,7 +116,7 @@ public function testSiteResolver() {
*/
public function testRevalidator() {
$blog_site = NextSite::create([
'id' => 'blog'
'id' => 'blog',
]);
$blog_site->save();

Expand Down
2 changes: 1 addition & 1 deletion modules/next/tests/src/Kernel/Entity/NextSiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function setUp(): void {
'id' => 'blog',
'base_url' => 'https://blog.com',
'preview_url' => 'https://blog.com/api/preview',
'preview_secret' => 'one'
'preview_secret' => 'one',
]);
$this->nextSite->save();

Expand Down
Loading

0 comments on commit 14813c4

Please sign in to comment.