neos / neos-development-collection

The unified repository containing the Neos core packages, used for Neos development.
https://www.neos.io/
GNU General Public License v3.0
260 stars 221 forks source link

!!! TASK: Make node label pure neos concept #5020

Closed mhsdesign closed 4 months ago

mhsdesign commented 5 months ago

Solves partially #5019

Upgrade instructions

To get the label for a Node in PHP, one must replace Node::getLabel() with a call to Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface::getLabel:

+  #[Flow\Inject]
+ protected NodeLabelGeneratorInterface $nodeLabelGenerator;
+ 
+ $this->nodeLabelGenerator->getLabel($node);
- $node->getLabel();

In Fusion accessing the label via ${node.label} will currently no longer work but one can leverage the flowquery ${q(node).label()} to get the label.

Additionally NodeType::getNodeLabelGenerator has been removed. Please inject the NodeLabelGeneratorInterface instead.

Review instructions

Followup node.label viewhelper for fluid (see also https://github.com/neos/neos-development-collection/issues/5023) Rector migrations will be provided as part of https://github.com/neos/rector/issues/57

The Label concept was removed from the core as it requires by its current implementation that the NodeType is available in the Node. Though there are ways to work around this by adding a label to the nodes constructor via some factory, seeing that the label is not used once in the core made us realise that this is just an arbitrary convenience thing attached to the core. To better have Neos' decide what it wants and how implementation / extensibility and co should look like we remove this concern from the core to also ease standalone use-cases.

Checklist

mhsdesign commented 5 months ago

The tests fail currently because Neos requires the Ui as well which is a bug: https://github.com/neos/neos-development-collection/issues/4951#issuecomment-2085427862

But when the ui is adjusted everything will work: https://github.com/neos/neos-ui/pull/3772

mhsdesign commented 4 months ago

We discussed that we want rather a flowquery operation for this for simplicity. Also i plan to make beta 10 not super super breaky but maybe even little forgiving so we can add this b/c and remove it with 11: The whole Node read model will consist of 50% deprecated code then mostly already because of https://github.com/neos/neos-development-collection/pull/5042 but thats fine imo this one time.

/**
 * Returned the node label as generated by the configured node label generator.
 *
 * In PHP please use Neos' {@see NodeLabelRenderer} instead.
 * 
 * For Fusion please use the FlowQuery operation:
 * ```
 * ${q(node).label()}
 * ```
 *
 * @deprecated will be removed before the final 9.0 release
 */
public function getLabel(): string
{
    // highly illegal
    return (new NodeLabelRenderer())->renderNodeLabel($this);
}