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

!!! TASK: Followup #4520 Introduce NodeType::tetheredNodeTypeDefinitions #4906

Merged
merged 13 commits into from
May 17, 2024

Conversation

mhsdesign
Copy link
Member

@mhsdesign mhsdesign commented Feb 20, 2024

Introduces new value objects TetheredNodeTypeDefinitions and TetheredNodeTypeDefinition (ported from #4999) to simplify NodeType and NodeTypeManager api.

Upgrade instructions

From 8.3

- foreach ($nodeType->getAutoCreatedChildNodes() as $rawNodeName => $childNodeType) {
-     $nodeName = NodeName::fromString($rawNodeName);
+ foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
+     $nodeName = $tetheredNodeTypeDefinition->name;
+     $childNodeType = $nodeTypeManager->getNodeType($tetheredNodeTypeDefinition->nodeTypeName);

- $nodeType->hasAutoCreatedChildNode($nodeName);
+ $nodeType->tetheredNodeTypeDefinitions->contain($nodeName);

- $parentsNodeType->getTypeOfAutoCreatedChildNode($nodeName)->name;
+ $parentsNodeType->tetheredNodeTypeDefinitions->get($nodeName)->nodeTypeName;

- $parentsNodeType->getTypeOfAutoCreatedChildNode($nodeName);
+ $nodeTypeManager->getNodeType($parentsNodeType->tetheredNodeTypeDefinitions->get($nodeName));

- $grandParentsNodeType->allowsGrandchildNodeType($parentNodeName->value, $nodeType);
+ $nodeTypeManager->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType->name, $parentNodeName, $nodeType->name);

For upgrade from 9.0-dev please note that the temporary methods: NodeTypeManager::getTetheredNodesConfigurationForNodeType, NodeTypeManager::getTypeOfTetheredNode, NodeType::hasTetheredNode and NodeType::getNodeTypeNameOfTetheredNode have been removed again and must be replaced with NodeType::$tetheredNodeTypeDefinitions

Review instructions

Ui part: neos/neos-ui#3782

Rector migrations will be provided as part of neos/rector#57

As said here #4520 (comment) writing

$nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeTypeManager->getNodeType($nodeTypeName))

feels not right, the nodeTypeManger should just operate on NodeTypeNames.

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

@github-actions github-actions bot added the 9.0 label Feb 20, 2024
@mhsdesign
Copy link
Member Author

As alternative trick we can as well make these hardcore mehtods internal like who really understands isNodeTypeAllowedAsChildToTetheredNode ?? :D Usages are limited to Neos.Neos and FlowpackNodeTemplates

@mhsdesign mhsdesign force-pushed the task/followup-4520-nodeTypeManger branch from 8dfe476 to e224d4a Compare April 3, 2024 19:28
@mhsdesign mhsdesign changed the title task/followup-4520-nodeTypeManger TASK: Followup #4520 nodeTypeManger Apr 3, 2024
@github-actions github-actions bot added the Task label Apr 3, 2024
@mhsdesign mhsdesign changed the title TASK: Followup #4520 nodeTypeManger !!! TASK: Followup #4520 NodeTypeManager should work on NodeTypeName Apr 3, 2024
@mhsdesign mhsdesign marked this pull request as ready for review April 3, 2024 19:31
@mhsdesign
Copy link
Member Author

Todo these rector migration would need to be adjusted so they dont pass the $nodeType to the methods, but $nodeType->name:

  • NodeTypeGetAutoCreatedChildNodesRector
  • NodeTypeGetTypeOfAutoCreatedChildNodeRector
  • NodeTypeAllowsGrandchildNodeTypeRector

@mhsdesign
Copy link
Member Author

@bwaidelich as you also currently refactor the NodeTypeManager (#4999) ... do you think we should also incorporate this change (i yet have to fix ci but just want to know if its worth the effort)

@bwaidelich
Copy link
Member

do you think we should also incorporate this change

We'll have to since Node::nodeType will most probably be removed

@mhsdesign mhsdesign force-pushed the task/followup-4520-nodeTypeManger branch from e224d4a to d14cc76 Compare May 1, 2024 12:11
Copy link
Contributor

@dlubitz dlubitz left a comment

Choose a reason for hiding this comment

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

Looks good in general. I stumled over the method names. Should we change them as we changed the parameter from NodeType to NodeTypeName?

E.g:
isNodeTypeAllowedAsChildToTetheredNode =>isNodeTypeNameAllowedAsChildToTetheredNode

@mhsdesign
Copy link
Member Author

Should we change them as we changed the parameter from NodeType to NodeTypeName?

good point but i dont think so as the thing the user of the api tries to solve if a NodeType is allowed or not ... that the node type is identified via NodeTypeName can be left out in the method name i think.


Another thing i just remembered is that we want to be rather forgiving (see #4954) so i dont know if all the new requireNodeType call would do us good or if they would be a pita in the future. Have to think if it makes sense to return false for booleans or just null otherwise.

@bwaidelich
Copy link
Member

isNodeTypeAllowedAsChildToTetheredNode =>isNodeTypeNameAllowedAsChildToTetheredNode

That doesn't make sense to me. Yes, we pass in a node name but this method is about the allowed node type

@mhsdesign mhsdesign force-pushed the task/followup-4520-nodeTypeManger branch from a00a096 to aa06847 Compare May 13, 2024 18:31
@mhsdesign mhsdesign force-pushed the task/followup-4520-nodeTypeManger branch from aa06847 to 9ad6b70 Compare May 14, 2024 19:07
Comment on lines +40 to +42
/** @phpstan-ignore-next-line */
public readonly TetheredNodeTypeDefinitions $tetheredNodeTypeDefinitions;

Copy link
Member Author

Choose a reason for hiding this comment

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

i applied a little hack here which is allowed even in php 8.3 and also documented. Its temporary but ugly.

All done to be forwards compatible with #4999, i just backported the TetheredNodeTypeDefinitions vo and NodeType::tetheredNodeTypeDefinitions

cc @bwaidelich

Copy link
Member Author

Choose a reason for hiding this comment

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

see also #4523 where i explain the hack and https://www.php.net/manual/en/language.oop5.properties.php

Readonly properties cannot be unset() once they are initialized. However, it is possible to unset a readonly property prior to initialization, from the scope where the property has been declared.

Copy link
Member Author

Choose a reason for hiding this comment

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

we (christian basti me) discussed that we want to go with this hack for now with the vision that the nodeType will be at one point a simple model like:

public function __construct(
  // ...
  public readonly TetheredNodeTypeDefinitions $tetheredNodeTypeDefinitions,
  // ...
) {}

Copy link
Member Author

Choose a reason for hiding this comment

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

As stated in #4228 (comment) we will probably NOT have that "planned"/ beloved followup in Neos 9 as this is a bigger one and requires lots of work.

The assumption was that the followup will go in and we can remove the __get hack again. We said for the (at that time) less likely event that the followup doesnt come, we will revert this and fallback to regular getters.

But there is one elephant in the room i was not aware of: Php8.4. It will come with support for such computed properties (see https://stitcher.io/blog/new-in-php-84#property-hooks-rfc) meaning we would have what we want at real language level supported.

The question is, can we live with this hack for the time until php 8.4 when we can refactor it to use the real get hook?
My worst fear, that php wouldnt support our syntax forever is gone now at least :D

Wdyt cc @kitsunet

@mhsdesign mhsdesign marked this pull request as draft May 14, 2024 19:10
…pe()`

Previously known as `NodeType::getAutoCreatedChildNodes`
@mhsdesign mhsdesign force-pushed the task/followup-4520-nodeTypeManger branch from 9ad6b70 to ab41496 Compare May 14, 2024 19:12
@mhsdesign mhsdesign marked this pull request as ready for review May 16, 2024 13:33
@mhsdesign mhsdesign changed the title !!! TASK: Followup #4520 NodeTypeManager should work on NodeTypeName !!! TASK: Followup #4520 Introduce NodeType::tetheredNodeTypeDefinitions May 17, 2024
Copy link
Member

@kitsunet kitsunet left a comment

Choose a reason for hiding this comment

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

👀

@kitsunet kitsunet merged commit b3d32bf into neos:9.0 May 17, 2024
10 checks passed
@mhsdesign mhsdesign deleted the task/followup-4520-nodeTypeManger branch May 17, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants