Component example

$element->setStartRow((int) $data['__emotionElement_start_row']);
        $element->setEndRow((int) $data['__emotionElement_end_row']);
        $element->setStartCol((int) $data['__emotionElement_start_col']);
        $element->setEndCol((int) $data['__emotionElement_end_col']);
        $element->setCssClass($data['__emotionElement_css_class']);

        return $element;
    }

    private function assignComponent(Element $element, array $data)
    {
        $component = new Component();

        $component->setId((int) $data['__emotionLibraryComponent_id']);
        $component->setName($data['__emotionLibraryComponent_name']);
        $component->setType($data['__emotionLibraryComponent_x_type']);
        $component->setConvertFunction($data['__emotionLibraryComponent_convert_function']);
        $component->setDescription($data['__emotionLibraryComponent_description']);
        $component->setTemplate($data['__emotionLibraryComponent_template']);
        $component->setCssClass($data['__emotionLibraryComponent_cls']);
        $component->setPluginId($data['__emotionLibraryComponent_plugin_id'] !== null ? (int) $data['__emotionLibraryComponent_plugin_id'] : null);

        $element->setComponent($component);
    }

  }

  /** * Tests that valid props are handled properly. * * @dataProvider dataProviderValidatePropsValid * * @throws \Drupal\sdc\Exception\InvalidComponentException */
  public function testValidatePropsValid(array $context, string $component_id, array $definition): void {
    $component = new Component(
      ['app_root' => '/fake/path/root'],
      'sdc_test:' . $component_id,
      $definition
    );
    $component_validator = new ComponentValidator();
    $component_validator->setValidator();
    $this->assertTrue(
      $component_validator->validateProps($context$component),
      'The valid component props threw an error.'
    );
  }

  
if (!$plugin) {
            throw new Exception(sprintf('Plugin by name %s not found', $pluginName));
        }

        $repo = $this->em->getRepository(Component::class);
        /** @var Component|null $component */
        $component = $repo->findOneBy([
            'name' => $componentName,
            'pluginId' => $plugin->getId(),
        ]);
        if (!$component) {
            $component = new Component();
        }

        $config = array_merge(static::COMPONENT_DEFAULTS, ['name' => $componentName]$data);
        $component->fromArray($config);
        $component->setPluginId($plugin->getId());
        $component->setPlugin($plugin);
        $plugin->getEmotionComponents()->add($component);

        return $component;
    }
}
Home | Imprint | This part of the site doesn't use cookies.