Skip to content

Commit

Permalink
feat(NodeType): Added attributable node-type field to display or no…
Browse files Browse the repository at this point in the history
…t nodes' attributes
  • Loading branch information
ambroisemaupate committed Oct 13, 2023
1 parent be5a594 commit 9206664
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20230828092821.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function down(Schema $schema): void
$this->addSql('DROP INDEX idx_user_created_at ON users');
$this->addSql('DROP INDEX idx_user_updated_at ON users');
}

public function isTransactional(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20230829082257.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function down(Schema $schema): void
$this->addSql('DROP INDEX idx_attribute_value_node_position ON attribute_values');
$this->addSql('DROP INDEX idx_attribute_value_position ON attribute_values');
}

public function isTransactional(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20230905140844.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function down(Schema $schema): void
$this->addSql('DROP INDEX IDX_319B9E709DFF5F89 ON attributes');
$this->addSql('ALTER TABLE attributes DROP realm_id');
}

public function isTransactional(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20230915134833.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function down(Schema $schema): void
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users ADD salt VARCHAR(64) NOT NULL');
}

public function isTransactional(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20231012154717.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function down(Schema $schema): void
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE documents DROP image_crop_alignment');
}

public function isTransactional(): bool
{
return false;
}
}
38 changes: 38 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20231013132932.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231013132932 extends AbstractMigration
{
public function getDescription(): string
{
return 'Added node-type attributable field';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE node_types ADD attributable TINYINT(1) DEFAULT 1 NOT NULL');
$this->addSql('CREATE INDEX IDX_409B1BCC1F470BBD ON node_types (attributable)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX IDX_409B1BCC1F470BBD ON node_types');
$this->addSql('ALTER TABLE node_types DROP attributable');
}

public function isTransactional(): bool
{
return false;
}
}
23 changes: 23 additions & 0 deletions lib/RoadizCoreBundle/src/Entity/NodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ORM\Index(columns: ["name"], name: "node_type_name"),
ORM\Index(columns: ["visible"]),
ORM\Index(columns: ["publishable"]),
ORM\Index(columns: ["attributable"]),
ORM\Index(columns: ["hiding_nodes"]),
ORM\Index(columns: ["hiding_non_reachable_nodes"]),
ORM\Index(columns: ["reachable"]),
Expand Down Expand Up @@ -89,6 +90,17 @@ class NodeType extends AbstractEntity implements NodeTypeInterface
Serializer\Type("boolean")
]
private bool $publishable = false;

/**
* @var bool Define if this node-type produces nodes that will have attributes.
*/
#[
ORM\Column(type: "boolean", nullable: false, options: ["default" => true]),
Serializer\Groups(["node_type"]),
SymfonySerializer\Groups(["node_type"]),
Serializer\Type("boolean")
]
private bool $attributable = false;
/**
* Define if this node-type produces nodes that will be
* viewable from a Controller.
Expand Down Expand Up @@ -520,4 +532,15 @@ public function setSearchable(bool $searchable): NodeType
$this->searchable = $searchable;
return $this;
}

public function isAttributable(): bool
{
return $this->attributable;
}

public function setAttributable(bool $attributable): NodeType
{
$this->attributable = $attributable;
return $this;
}
}
2 changes: 1 addition & 1 deletion lib/RoadizRozierBundle/templates/nodes/navBar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
href="{{ path('nodesEditTagsPage', { nodeId: node.id}) }}">{% trans %}tags{% endtrans %}</a>
</li>
{% endif %}
{% if is_granted('EDIT_ATTRIBUTE', node) %}
{% if is_granted('EDIT_ATTRIBUTE', node) and node.nodeType.attributable %}
<li class="uk-navbar-item{% if current == 'attributes' %} uk-active{% endif %}">
<a class="uk-navbar-link" href="{{ path('nodesEditAttributesPage', {
nodeId: node.id,
Expand Down
21 changes: 19 additions & 2 deletions lib/Rozier/src/Controllers/Nodes/NodesAttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use RZ\Roadiz\CoreBundle\Entity\AttributeValueTranslation;
use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\NodeType;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Event\NodesSources\NodesSourcesUpdatedEvent;
use RZ\Roadiz\CoreBundle\Form\AttributeValueTranslationType;
Expand Down Expand Up @@ -67,6 +68,10 @@ public function editAction(Request $request, int $nodeId, int $translationId): R
throw $this->createNotFoundException('Node-source does not exist');
}

if (!$this->isAttributable($node)) {
throw $this->createNotFoundException('Node type is not attributable');
}

if (null !== $response = $this->handleAddAttributeForm($request, $node, $translation)) {
return $response;
}
Expand Down Expand Up @@ -120,7 +125,7 @@ public function editAction(Request $request, int $nodeId, int $translationId): R
return new JsonResponse([
'status' => 'success',
'message' => $msg,
], JsonResponse::HTTP_ACCEPTED);
], Response::HTTP_ACCEPTED);
}
return $this->redirectToRoute('nodesEditAttributesPage', [
'nodeId' => $node->getId(),
Expand All @@ -136,7 +141,7 @@ public function editAction(Request $request, int $nodeId, int $translationId): R
'status' => 'fail',
'errors' => $errors,
'message' => $this->getTranslator()->trans('form_has_errors.check_you_fields'),
], JsonResponse::HTTP_BAD_REQUEST);
], Response::HTTP_BAD_REQUEST);
}
foreach ($errors as $error) {
$this->publishErrorMessage($request, $error);
Expand All @@ -163,6 +168,15 @@ protected function hasAttributes(): bool
return $this->em()->getRepository(Attribute::class)->countBy([]) > 0;
}

protected function isAttributable(Node $node): bool
{
$nodeType = $node->getNodeType();
if ($nodeType instanceof NodeType) {
return $nodeType->isAttributable();
}
return false;
}

/**
* @param Request $request
* @param Node $node
Expand All @@ -172,6 +186,9 @@ protected function hasAttributes(): bool
*/
protected function handleAddAttributeForm(Request $request, Node $node, Translation $translation): ?RedirectResponse
{
if (!$this->isAttributable($node)) {
return null;
}
if (!$this->hasAttributes()) {
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Rozier/src/Forms/NodeTypeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'required' => false,
'help' => 'enables_published_at_field_for_time_based_publication',
])
->add('attributable', CheckboxType::class, [
'label' => 'attributable',
'required' => false,
'help' => 'enables_node_attributes_for_this_type',
])
->add('reachable', CheckboxType::class, [
'label' => 'reachable',
'required' => false,
Expand Down
3 changes: 3 additions & 0 deletions lib/Rozier/src/Resources/translations/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,9 @@
<trans-unit xml:space="preserve" id="image_crop_alignment.bottom-left"><source>image_crop_alignment.bottom-left</source></trans-unit>
<trans-unit xml:space="preserve" id="image_crop_alignment.bottom"><source>image_crop_alignment.bottom</source></trans-unit>
<trans-unit xml:space="preserve" id="image_crop_alignment.bottom-right"><source>image_crop_alignment.bottom-right</source></trans-unit>

<trans-unit xml:space="preserve" id="attributable"><source>attributable</source></trans-unit>
<trans-unit xml:space="preserve" id="enables_node_attributes_for_this_type"><source>enables_node_attributes_for_this_type</source></trans-unit>
</body>
</file>
</xliff>
1 change: 1 addition & 0 deletions src/Resources/node-types/Article.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Article",
"visible": true,
"publishable": true,
"attributable": false,
"reachable": true,
"hiding_nodes": false,
"hiding_non_reachable_nodes": true,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/ArticleContainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"display_name": "Article container",
"visible": true,
"publishable": false,
"attributable": true,
"reachable": true,
"hiding_nodes": true,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/ArticleFeedBlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"display_name": "Article feed block",
"visible": true,
"publishable": false,
"attributable": false,
"reachable": false,
"hiding_nodes": true,
"hiding_non_reachable_nodes": true,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/BasicBlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"display_name": "Basic Block",
"visible": false,
"publishable": false,
"attributable": false,
"reachable": false,
"hiding_nodes": false,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/GroupBlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"display_name": "Group block",
"visible": true,
"publishable": false,
"attributable": false,
"reachable": false,
"hiding_nodes": false,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/Menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"display_name": "Menu",
"visible": true,
"publishable": false,
"attributable": true,
"reachable": false,
"hiding_nodes": false,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/MenuLink.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"display_name": "Lien du menu",
"visible": false,
"publishable": false,
"attributable": true,
"reachable": false,
"hiding_nodes": false,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/Neutral.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Neutral",
"visible": true,
"publishable": false,
"attributable": false,
"reachable": false,
"hiding_nodes": false,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/Offer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Offer",
"visible": true,
"publishable": false,
"attributable": true,
"reachable": true,
"hiding_nodes": false,
"hiding_non_reachable_nodes": false,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/node-types/Page.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Page",
"visible": true,
"publishable": true,
"attributable": true,
"reachable": true,
"hiding_nodes": false,
"hiding_non_reachable_nodes": true,
Expand Down

0 comments on commit 9206664

Please sign in to comment.