Skip to content

Commit

Permalink
Feature: Adjust rendering of backend module from fluid to fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
mficzel committed Jan 10, 2023
1 parent a5d603b commit 5283e51
Show file tree
Hide file tree
Showing 21 changed files with 520 additions and 483 deletions.
87 changes: 46 additions & 41 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function changeContextAction($targetAction, $targetProperty, NodeInterfac
$newContextProperties['targetDimensions'][$dimensionName] = $presetName;
}
$modifiedContext = $this->contextFactory->create(array_merge($contextProperties, $newContextProperties));

$nodeInModifiedContext = $modifiedContext->getNodeByIdentifier($contextNode->getIdentifier());

$this->redirect($targetAction, null, null, [$targetProperty => $nodeInModifiedContext]);
Expand Down Expand Up @@ -277,24 +278,27 @@ public function newVocabularyAction(NodeInterface $taxonomyRoot)
* Create a new vocabulary
*
* @param NodeInterface $taxonomyRoot
* @param string $title
* @param string $description
* @param array $properties
* @return void
*/
public function createVocabularyAction(NodeInterface $taxonomyRoot, $title, $description = '')
public function createVocabularyAction(NodeInterface $taxonomyRoot, array $properties)
{
$vocabularyNodeType = $this->nodeTypeManager->getNodeType($this->taxonomyService->getVocabularyNodeType());
$vocabularyProperties = $vocabularyNodeType->getProperties();

$nodeTemplate = new NodeTemplate();
$nodeTemplate->setNodeType($vocabularyNodeType);
$nodeTemplate->setName(CrUtitlity::renderValidNodeName($title));
$nodeTemplate->setProperty('title', $title);
$nodeTemplate->setProperty('description', $description);
$nodeTemplate->setName(CrUtitlity::renderValidNodeName($properties['title']));
foreach($properties as $name => $value) {
if (array_key_exists($name, $vocabularyProperties)) {
$nodeTemplate->setProperty($name, $value);
}
}

$vocabulary = $taxonomyRoot->createNodeFromTemplate($nodeTemplate);

$this->addFlashMessage(
sprintf('Created vocabulary %s at path %s', $title, $vocabulary->getPath())
sprintf('Created vocabulary %s at path %s', $properties['title'], $vocabulary->getLabel())
);
$this->redirect('index', null, null, ['root' => $taxonomyRoot]);
}
Expand All @@ -317,26 +321,24 @@ public function editVocabularyAction(NodeInterface $vocabulary)
* Apply changes to the given vocabulary
*
* @param NodeInterface $vocabulary
* @param string $title
* @param string $description
* @param array $properties
* @return void
*/
public function updateVocabularyAction(NodeInterface $vocabulary, $title, $description = '')
public function updateVocabularyAction(NodeInterface $vocabulary, array $properties)
{
$taxonomyRoot = $this->taxonomyService->getRoot($vocabulary->getContext());
$previousTitle = $vocabulary->getProperty('title');
$previousDescription = $vocabulary->getProperty('description');

if ($previousTitle !== $title) {
$vocabulary->setProperty('title', $title);
}

if ($previousDescription !== $description) {
$vocabulary->setProperty('description', $description);
$vocabularyProperties = $vocabulary->getNodeType()->getProperties();
foreach($properties as $name => $value) {
if (array_key_exists($name, $vocabularyProperties)) {
$previous = $vocabulary->getProperty($name);
if ($previous !== $value) {
$vocabulary->setProperty($name, $value);
}
}
}

$this->addFlashMessage(
sprintf('Updated vocabulary %s', $title)
sprintf('Updated vocabulary %s', $vocabulary->getLabel())
);
$this->redirect('index', null, null, ['root' => $taxonomyRoot]);
}
Expand Down Expand Up @@ -381,22 +383,28 @@ public function newTaxonomyAction(NodeInterface $parent)
* Create a new taxonomy
*
* @param NodeInterface $parent
* @param string $title
* @param string $description
* @param array $properties
* @return void
*/
public function createTaxonomyAction(NodeInterface $parent, $title, $description = '')
public function createTaxonomyAction(NodeInterface $parent, array $properties)
{
$taxonomyNodeType = $this->nodeTypeManager->getNodeType($this->taxonomyService->getTaxonomyNodeType());
$taxomonyProperties = $taxonomyNodeType->getProperties();

$nodeTemplate = new NodeTemplate();
$nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType($this->taxonomyService->getTaxonomyNodeType()));
$nodeTemplate->setName(CrUtitlity::renderValidNodeName($title));
$nodeTemplate->setProperty('title', $title);
$nodeTemplate->setProperty('description', $description);
$nodeTemplate->setNodeType($taxonomyNodeType);
$nodeTemplate->setName(CrUtitlity::renderValidNodeName($properties['title']));

foreach($properties as $name => $value) {
if (array_key_exists($name, $taxomonyProperties)) {
$nodeTemplate->setProperty($name, $value);
}
}

$taxonomy = $parent->createNodeFromTemplate($nodeTemplate);

$this->addFlashMessage(
sprintf('Created taxonomy %s at path %s', $title, $taxonomy->getPath())
sprintf('Created taxonomy %s at path %s', $taxonomy->getLabel(), $taxonomy->getPath())
);

$flowQuery = new FlowQuery([$taxonomy]);
Expand Down Expand Up @@ -430,28 +438,25 @@ public function editTaxonomyAction(NodeInterface $taxonomy)

$this->view->assign('taxonomy', $taxonomy);
$this->view->assign('defaultTaxonomy', $this->getNodeInDefaultDimensions($taxonomy));

}

/**
* Apply changes to the given taxonomy
*
* @param NodeInterface $taxonomy
* @param string $title
* @param string $description
* @param array $properties
* @return void
*/
public function updateTaxonomyAction(NodeInterface $taxonomy, $title, $description = '')
public function updateTaxonomyAction(NodeInterface $taxonomy, array $properties)
{
$previousTitle = $taxonomy->getProperty('title');
$previousDescription = $taxonomy->getProperty('description');

if ($previousTitle !== $title) {
$taxonomy->setProperty('title', $title);
}

if ($previousDescription !== $description) {
$taxonomy->setProperty('description', $description);
$taxonomyProperties = $taxonomy->getNodeType()->getProperties();
foreach($properties as $name => $value) {
if (array_key_exists($name, $taxonomyProperties)) {
$previous = $taxonomy->getProperty($name);
if ($previous !== $value) {
$taxonomy->setProperty($name, $value);
}
}
}

$this->addFlashMessage(
Expand Down
6 changes: 6 additions & 0 deletions Configuration/Views.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-
requestFilter: 'isPackage("Sitegeist.Taxonomy") && isController("Module")'
viewObjectName: 'Neos\Fusion\View\FusionView'
options:
fusionPathPatterns:
- 'resource://Sitegeist.Taxonomy/Private/Fusion/Backend'
32 changes: 32 additions & 0 deletions Resources/Private/Fusion/Backend/Fragments/LanguageSelector.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
prototype(Sitegeist.Taxonomy:Views.Fragments.LanguageSelector) < prototype(Neos.Fusion:Component) {

targetAction = null
targetProperty = null
contentDimensionOptions = null
contextNode = null

renderer = afx`
<Neos.Fusion.Form:Form @if={props.contextNode}
form.target.action="changeContext"
form.data.dimensions={props.contextNode.context.targetDimensions}
attributes.class="neos-inline"
form.method="get"
>
<Neos.Fusion.Form:Hidden field.name="contextNode" field.value={props.contextNode.contextPath} />
<Neos.Fusion.Form:Hidden field.name="targetAction" field.value={props.targetAction} />
<Neos.Fusion.Form:Hidden field.name="targetProperty" field.value={props.targetProperty} />

<Neos.Fusion:Loop items={props.contentDimensionOptions} itemName="dimensionConfiguration" itemKey="dimensionKey">
<Neos.Fusion.Form:Select
field.name={"dimensions[" + dimensionKey + "]"}
attributes.onchange="this.form.submit()"
>
<Neos.Fusion:Loop items={dimensionConfiguration.presets} itemName="presetName" itemKey="presetIdentifier">
<Neos.Fusion.Form:Select.Option option.value={presetIdentifier}>{presetName}</Neos.Fusion.Form:Select.Option>
</Neos.Fusion:Loop>
</Neos.Fusion.Form:Select>
</Neos.Fusion:Loop>

</Neos.Fusion.Form:Form>
`
}
12 changes: 12 additions & 0 deletions Resources/Private/Fusion/Backend/Root.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include: resource://Neos.Fusion/Private/Fusion/Root.fusion
include: resource://Neos.Fusion.Form/Private/Fusion/Root.fusion
include: **/*.fusion


Sitegeist.Taxonomy.ModuleController.index = Sitegeist.Taxonomy:Views.Module.Vocabulary.List
Sitegeist.Taxonomy.ModuleController.newVocabulary = Sitegeist.Taxonomy:Views.Module.Vocabulary.New
Sitegeist.Taxonomy.ModuleController.editVocabulary = Sitegeist.Taxonomy:Views.Module.Vocabulary.Edit

Sitegeist.Taxonomy.ModuleController.vocabulary = Sitegeist.Taxonomy:Views.Module.Taxonomy.List
Sitegeist.Taxonomy.ModuleController.newTaxonomy = Sitegeist.Taxonomy:Views.Module.Taxonomy.New
Sitegeist.Taxonomy.ModuleController.editTaxonomy = Sitegeist.Taxonomy:Views.Module.Taxonomy.Edit
45 changes: 45 additions & 0 deletions Resources/Private/Fusion/Backend/Views/Taxonomy.Edit.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
prototype(Sitegeist.Taxonomy:Views.Module.Taxonomy.Edit) < prototype(Neos.Fusion:Component) {

i18nMain = ${Translation.value('').package("Sitegeist.Taxonomy").source('Main')}
i18nVocabulary = ${Translation.value('').package("Sitegeist.Taxonomy").source('NodeTypes/Vocabulary')}
i18nTaxonomy = ${Translation.value('').package("Sitegeist.Taxonomy").source('NodeTypes/Taxonomy')}

renderer = afx`
<legend>{props.i18nMain.id('taxon')}: {taxonomy.properties.title}</legend>
<legend @if={defaultTaxonomy}>{props.i18nMain.id('generic.default')}: {defaultTaxonomy.properties.title}</legend>

<Neos.Fusion.Form:Form form.target.action="updateTaxonomy" form.data.properties={taxonomy.properties}>
<Neos.Fusion.Form:Hidden field.name="taxonomy" field.value={taxonomy.contextPath} />

<fieldset>
<div class="neos-control-group">
<label class="neos-control-label" for="title">
{props.i18nTaxonomy.id('properties.title')}
<span @if={defaultTaxonomy}>: {defaultTaxonomy.properties.title}</span>
</label>
<Neos.Fusion.Form:Textarea attributes.class="neos-span6" field.name="properties[title]" />
</div>

<div class="neos-control-group">
<label class="neos-control-label" for="description">
{props.i18nTaxonomy.id('properties.description')}
<span @if={defaultTaxonomy}>: {defaultTaxonomy.properties.description}</span>
</label>
<Neos.Fusion.Form:Textarea attributes.class="neos-span6 form-inline" field.name="properties[description]"/>
</div>

<div class="neos-control-group">
<Neos.Fusion:Link.Action
class="neos-button"
href.action="vocabulary"
href.arguments.vocabulary={vocabulary}
>
{props.i18nMain.id('generic.cancel')}
</Neos.Fusion:Link.Action>
<Neos.Fusion.Form:Button attributes.class="neos-button neos-button-primary">{props.i18nMain.id('generic.save') + ''}</Neos.Fusion.Form:Button>
</div>
</fieldset>
</Neos.Fusion.Form:Form>
`

}
Loading

0 comments on commit 5283e51

Please sign in to comment.