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, 2024
1 parent 43ffaec commit d655839
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 76 deletions.
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
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;
}

}

0 comments on commit d655839

Please sign in to comment.