示例#1
0
 /**
  * Test andModelIs filter.
  *
  * @dataProvider provideForAndModelIdIs()
  */
 public function testAndModelIdIs($expected, $modelId1, $modelId2)
 {
     $filter = new Filter();
     $item = new MockedAbstractItem(ItemInterface::CREATE, null, $modelId1);
     $filter->andSub(new MockedFilter(true));
     $filter->andModelIs($modelId2);
     $this->assertEquals($expected, $filter->accepts($item));
 }
示例#2
0
 /**
  * Generate the paste button.
  *
  * @param GetPasteButtonEvent $event The event.
  *
  * @return void
  */
 public function generatePasteButton(GetPasteButtonEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_filtersetting') {
         return;
     }
     $environment = $event->getEnvironment();
     $model = $event->getModel();
     $clipboard = $environment->getClipboard();
     $filter = new Filter();
     $filter->andModelIs(ModelId::fromModel($model))->andActionIs($clipboard::MODE_CUT);
     // Disable all buttons if there is a circular reference.
     if ($event->isCircularReference() || !$clipboard->isEmpty($filter)) {
         $event->setPasteAfterDisabled(true)->setPasteIntoDisabled(true);
         return;
     }
     $factory = $this->getServiceContainer()->getFilterFactory()->getTypeFactory($model->getProperty('type'));
     // If setting does not support children, omit them.
     if ($model->getId() && !($factory && $factory->isNestedType())) {
         $event->setPasteIntoDisabled(true);
     }
 }