Newer
Older
namespace SGalinski\TypoScriptReferenceFrontend\Controller;
/* *
* This script belongs to the TYPO3 Flow package "SGalinski.TypoScriptReferenceFrontend".*
* *
* */
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Attribute;
use SGalinski\TypoScriptReferenceFrontend\Service\TsrefRestService;
use SGalinski\TypoScriptReferenceFrontend\Utilities\Conversion;
class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
* @var TsrefRestService
*/
protected $tsrefRestService;
/**
* @var \TYPO3\Flow\Security\Context
*/
protected $securityContext;
/**
* The constructor is used for dependency injection.
*
* @param TsrefRestService $service
*/
public function __construct(TsrefRestService $service) {
$this->tsrefRestService = $service;
}
/**
* Injects the security context
*
* @param \TYPO3\Flow\Security\Context $securityContext The security context
* @return void
*/
public function injectSecurityContext(\TYPO3\Flow\Security\Context $securityContext) {
$this->securityContext = $securityContext;
}
* The action which fetches the data for typoScript reference page, and displays the page.
* @param string $typeUrlName - typeUrlName
public function indexAction($typeUrlName = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL) {
if ($typeUrlName !== NULL) {
$selectedType = $this->tsrefRestService->getTypeByUrlName($typeUrlName);
damjan
committed
$properties = $this->tsrefRestService->getPropertiesByParentId($selectedType->id);
$this->view->assign('properties', $properties);
$this->view->assign('selectedType', $selectedType);
// If the type extends a type (superType), the superType name is being fetched among other fields
if (isset($selectedType->parent_id)) {
$superType = $this->tsrefRestService->getAttributeById($selectedType->parent_id);
$this->view->assign('superType', $superType);
}
// $account = $this->securityContext->getAccount(); // TODO: Check if user is admin, view helper can be used
$this->prepareTypeMenu((isset($selectedType) ? $selectedType->urlName : NULL), $typo3Version);
* Adds a new type or saves changes in edited type.
* @param string $typo3Version
* @throws \TYPO3\Flow\Mvc\Exception\ForwardException
Attribute $theType, $editForm, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
if ($theType->getParent() === -1) {
$theType->setParent(NULL);
}
$result = $this->tsrefRestService->editAttribute($theType);
$result = $this->tsrefRestService->addNewAttribute($theType);
// TODO: get edited type and use its urlName to redirect to
'index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend',
['typeUrlName' => $theType->getUrlName(), 'typo3Version' => $typo3Version]
}
/**
* Prepares and opens the page for adding new / editing the type
public function editTypeAction($typeId = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL) {
$selectedTypeAsStdClass = $this->tsrefRestService->getAttributeById($typeId);
$theType->initialiseAttribute($selectedTypeAsStdClass);
}
$this->prepareTypeMenu($theType->getUrlName(), $typo3Version);
$typo3Groups = $this->tsrefRestService->getAllTypo3Groups();
$selectMenuTypes = $this->tsrefRestService->getTypesWithNull($typo3Version);
$this->view->assign('typo3Groups', $typo3Groups);
$this->view->assign('theType', $theType);
$this->view->assign('editForm', ($typeId !== NULL));
$this->view->assign('selectMenuTypes', $selectMenuTypes);
/**
* Adds a new property or saves the changes in edited property.
*
* @param Attribute $theProperty
* @param boolean $editForm
* @param string $typo3Version
* @throws \TYPO3\Flow\Mvc\Exception\ForwardException
* @return void
*/
Attribute $theProperty, $editForm, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
if ($editForm) {
$result = $this->tsrefRestService->editAttribute($theProperty);
} else {
$result = $this->tsrefRestService->addNewAttribute($theProperty);
}
// TODO: Return error message. Or success message.
$parentType = $this->tsrefRestService->getAttributeById($theProperty->getParent());
'index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend',
['typeUrlName' => ($parentType ? $parentType->urlName : NULL), 'typo3Version' => $typo3Version]
);
}
/**
* Prepares and opens the page for adding new / editing the property
*
* @param int $parentTypeId
* @param int $thePropertyId
$parentTypeId, $thePropertyId = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
$theProperty = new Attribute();
if ($thePropertyId !== NULL) {
// Edit type
$selectedPropertyAsStdClass = $this->tsrefRestService->getAttributeById($thePropertyId);
$theProperty->initialiseAttribute($selectedPropertyAsStdClass);
}
$theProperty->setParent($parentTypeId);
$parentType = $this->tsrefRestService->getAttributeById($parentTypeId);
$this->prepareTypeMenu(($parentType ? $parentType->urlName : NULL), $typo3Version);
$typo3Groups = $this->tsrefRestService->getAllTypo3Groups();
$selectMenuTypes = Conversion::toAssociativeIdArray($this->tsrefRestService->getTypes(TRUE, $typo3Version));
$this->view->assign('typo3Groups', $typo3Groups);
$this->view->assign('theProperty', $theProperty);
$this->view->assign('editForm', ($thePropertyId !== NULL));
$this->view->assign('selectMenuTypes', $selectMenuTypes);
/**
* Deletes attribute by $attributeId.
* If the attribute is a type, $parentTypeUrlName should be NULL.
* If the attribute is a property, $parentTypeUrlName should be specified,
* and then that type will be presented after deletion of the property.
*
* @param int $attributeId
* @param string $parentTypeUrlName
$attributeId, $parentTypeUrlName = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
$result = $this->tsrefRestService->patchAttribute($attributeId, ['deleted' => TRUE]);
// TODO: Return error message. Or success message.
'index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend',
['typeUrlName' => $parentTypeUrlName, 'typo3Version' => $typo3Version]
);
}
/**
* Submits typo3 version to be used in filtering.
*
* @param string $submittedTypo3Version
* @throws \TYPO3\Flow\Mvc\Exception\ForwardException
* @return void
*/
public function submitTypo3VersionAction($submittedTypo3Version) {
'index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend', ['typo3Version' => $submittedTypo3Version]
/**
* Sets view variables needed for type menu.
*
* @param int $selectedTypeUrlName
* @param string $selectedTypo3Version
* @return void
protected function prepareTypeMenu($selectedTypeUrlName, $selectedTypo3Version) {
$typo3VersionFilter = $this->decodeSelectedTypo3Version($selectedTypo3Version);
$types = $this->tsrefRestService->getTypes(TRUE, $typo3VersionFilter);
$typo3Versions = $this->tsrefRestService->getTypo3Versions();
$associativeTypes = Conversion::toAssociativeUrlNamesArray($types);
$this->view->assign('menuTypes', $associativeTypes);
$this->view->assign('selectedTypeUrlName', $selectedTypeUrlName);
$this->view->assign('typo3Versions', $typo3Versions);
$this->view->assign('selectedTypo3Version', $selectedTypo3Version);
/**
* Translates TYPO3 version selection from user-friendly value to actual value
* which is used in backend for filtering.
*
* @param $selectedTypo3Version
* @return null|string
*/
protected function decodeSelectedTypo3Version($selectedTypo3Version) {
if (strcasecmp($selectedTypo3Version, TsrefRestService::TYPO3_CURRENT_VERSION_LABEL) === 0) {
return TsrefRestService::TYPO3_DEFAULT_VERSION;
}
if (strcasecmp($selectedTypo3Version, 'all') === 0) {
return NULL;
}
return $selectedTypo3Version;
}