Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Allow developers to define their own view #1784

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Classes/Controller/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use GeorgRinger\News\Event\NewsCheckPidOfNewsRecordFailedInDetailActionEvent;
use GeorgRinger\News\Event\NewsDateMenuActionEvent;
use GeorgRinger\News\Event\NewsDetailActionEvent;
use GeorgRinger\News\Event\NewsInitializeActionEvent;
use GeorgRinger\News\Event\NewsListActionEvent;
use GeorgRinger\News\Event\NewsListSelectedActionEvent;
use GeorgRinger\News\Event\NewsSearchFormActionEvent;
Expand All @@ -26,6 +27,7 @@
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Fluid\View\TemplateView;
Expand Down Expand Up @@ -116,6 +118,15 @@ public function initializeAction()
$cacheTagsSet = true;
}
}
/** @var NewsInitializeActionEvent $event */
$event = $this->eventDispatcher->dispatch(
new NewsInitializeActionEvent(
$this,
$this->defaultViewObjectName,
$this->request->getControllerActionName()
)
);
$this->defaultViewObjectName = $event->getDefaultViewObjectName();
}

/**
Expand Down Expand Up @@ -700,4 +711,9 @@ public function setView(TemplateView $view): void
{
$this->view = $view;
}

public function getView(): ViewInterface
{
return $this->view;
}
}
8 changes: 4 additions & 4 deletions Classes/Domain/Model/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class News extends AbstractEntity
protected $l10nParent = 0;

/**
* @var DateTime
* @var DateTime|null
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really unsure if that breaks in 10 because extbase can't get the type anymore of

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave those changes, also imo not related to this feature, correct?

*/
protected $starttime;
protected $starttime = null;

/**
* @var DateTime
* @var DateTime|null
*/
protected $endtime;
protected $endtime = null;

/**
* keep it as string as it should be only used during imports
Expand Down
90 changes: 90 additions & 0 deletions Classes/Event/NewsInitializeActionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);

AKaravas marked this conversation as resolved.
Show resolved Hide resolved
namespace GeorgRinger\News\Event;

use GeorgRinger\News\Controller\NewsController;

/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
final class NewsInitializeActionEvent
{
private $newsController;
AKaravas marked this conversation as resolved.
Show resolved Hide resolved

private $defaultViewObjectName;

private $action;

/**
* @param NewsController $newsController
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All not required, pleas remove

* @param string $defaultViewObjectName
* @param string $action
*/
public function __construct(NewsController $newsController, string $defaultViewObjectName, string $action = '')
{
$this->newsController = $newsController;
$this->defaultViewObjectName = $defaultViewObjectName;
$this->action = $action;
}

/**
* @return NewsController
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required, can be removed

*/
public function getNewsController(): NewsController
{
return $this->newsController;
}

/**
* @param NewsController $newsController
* @return $this
*/
public function setNewsController(NewsController $newsController): self
{
$this->newsController = $newsController;

return $this;
}

/**
* @return string
*/
public function getDefaultViewObjectName(): string
{
return $this->defaultViewObjectName;
}

/**
* @param string $defaultViewObjectName
* @return NewsInitializeActionEvent
*/
public function setDefaultViewObjectName(string $defaultViewObjectName): self
{
$this->defaultViewObjectName = $defaultViewObjectName;

return $this;
}

/**
* @return string
*/
public function getAction(): string
{
return $this->action;
}

/**
* @param string $action
* @return NewsInitializeActionEvent
*/
public function setAction(string $action): self
{
$this->action = $action;

return $this;
}
}
1 change: 1 addition & 0 deletions Documentation/Reference/Events/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fired. For additional items see column "Access to" in the table below.
"NewsListSelectedActionEvent", "NewsController", "getAssignedValues()", "selectedListAction (NewsController::SIGNAL_NEWS_LIST_SELECTED_ACTION)"
"NewsSearchFormActionEvent", "NewsController", "getAssignedValues()", "searchFormAction (NewsController::SIGNAL_NEWS_SEARCHFORM_ACTION)"
"NewsSearchResultActionEvent", "NewsController", "getAssignedValues()", "searchResultAction (NewsController::SIGNAL_NEWS_SEARCHRESULT_ACTION)"
"NewsInitializeActionEvent", "NewsController", "getDefaultViewObjectName();getAction()", ""
"AdministrationIndexActionEvent", "AdministrationController", "getAssignedValues()", "indexAction (AdministrationController::SIGNAL_ADMINISTRATION_INDEX_ACTION)"
"AdministrationNewsPidListingActionEvent", "AdministrationController", "getRawTree();getTreeLevel()", "newsPidListingAction (AdministrationController::SIGNAL_ADMINISTRATION_NEWSPIDLISTING_ACTION)"
"AdministrationExtendMenuEvent", "AdministrationController", "getMenu()", "createMenu"
Expand Down