33
33
use ContaoCommunityAlliance \DcGeneral \Contao \View \Contao2BackendView \Event \ModelToLabelEvent ;
34
34
use ContaoCommunityAlliance \DcGeneral \Contao \View \Contao2BackendView \Event \ManipulateWidgetEvent ;
35
35
use ContaoCommunityAlliance \DcGeneral \Controller \ModelCollector ;
36
+ use ContaoCommunityAlliance \DcGeneral \Controller \RelationshipManager ;
36
37
use ContaoCommunityAlliance \DcGeneral \Data \ModelId ;
38
+ use ContaoCommunityAlliance \DcGeneral \Data \ModelInterface ;
37
39
use ContaoCommunityAlliance \DcGeneral \EnvironmentInterface ;
38
40
use ContaoCommunityAlliance \DcGeneral \Factory \DcGeneralFactory ;
39
41
use ContaoCommunityAlliance \Translator \TranslatorInterface ;
@@ -210,9 +212,6 @@ public function handleModelToLabel(ModelToLabelEvent $event)
210
212
* @param GetPasteButtonEvent $event The event.
211
213
*
212
214
* @return void
213
- *
214
- * @SuppressWarnings(PHPMD.Superglobals)
215
- * @SuppressWarnings(PHPMD.CamelCaseVariableName)
216
215
*/
217
216
public function generatePasteButton (GetPasteButtonEvent $ event )
218
217
{
@@ -234,18 +233,19 @@ public function generatePasteButton(GetPasteButtonEvent $event)
234
233
return ;
235
234
}
236
235
237
- $ flags = $ GLOBALS ['METAMODELS ' ]['inputscreen_conditions ' ][$ model ->getProperty ('type ' )];
238
236
// If setting does not support children, omit them.
239
- if ($ model ->getId () &&
240
- (!$ flags ['nestingAllowed ' ])
241
- ) {
237
+ $ collector = new ModelCollector ($ environment );
238
+ if ($ model ->getId () && !$ this ->acceptsAnotherChild ($ model , $ collector )) {
242
239
$ event ->setPasteIntoDisabled (true );
243
- return ;
244
240
}
245
241
246
- $ collector = new ModelCollector ($ environment );
247
- if (isset ($ flags ['maxChildren ' ]) && count ($ collector ->collectChildrenOf ($ model )) > $ flags ['maxChildren ' ]) {
248
- $ event ->setPasteIntoDisabled (true );
242
+ $ definition = $ environment ->getDataDefinition ();
243
+ $ mode = $ definition ->getBasicDefinition ()->getMode ();
244
+ $ relationships = new RelationshipManager ($ definition ->getModelRelationshipDefinition (), $ mode );
245
+ if (!$ relationships ->isRoot ($ model )
246
+ && ($ parent = $ collector ->searchParentOf ($ model ))
247
+ && !$ this ->acceptsAnotherChild ($ parent , $ collector )) {
248
+ $ event ->setPasteAfterDisabled (true );
249
249
}
250
250
}
251
251
@@ -488,6 +488,33 @@ public function encodeValueValue(EncodePropertyValueFromWidgetEvent $event)
488
488
}
489
489
}
490
490
491
+ /**
492
+ * Test if a model accepts another child.
493
+ *
494
+ * @param ModelInterface $model The model that shall be checked.
495
+ * @param ModelCollector $collector The collector to use.
496
+ *
497
+ * @return bool
498
+ *
499
+ * @SuppressWarnings(PHPMD.Superglobals)
500
+ * @SuppressWarnings(PHPMD.CamelCaseVariableName)
501
+ */
502
+ private function acceptsAnotherChild (ModelInterface $ model , ModelCollector $ collector )
503
+ {
504
+ $ conditionType = $ model ->getProperty ('type ' );
505
+ $ flags = $ GLOBALS ['METAMODELS ' ]['inputscreen_conditions ' ][$ conditionType ];
506
+ if (!$ flags ['nestingAllowed ' ]) {
507
+ return false ;
508
+ }
509
+
510
+ if (isset ($ flags ['maxChildren ' ])
511
+ && count ($ collector ->collectDirectChildrenOf ($ model )) > $ flags ['maxChildren ' ]) {
512
+ return false ;
513
+ }
514
+
515
+ return true ;
516
+ }
517
+
491
518
/**
492
519
* Obtain the values of a property within a dc-general instance.
493
520
*
0 commit comments