CRUDlex\Service

class Service

The Service setups and initializes the whole CRUD system and is initialized via the framework specific implementation, the Silex one for example. It offers access to AbstractData instances, one for each defined entity off the CRUD YAML file and various other helper functions.

property datas

protected array

Holds the data instances.

property templates

protected array

Holds the map for overriding templates.

property manageI18n

protected bool

Holds whether CRUDlex manages i18n.

property urlGenerator

protected SymfonyComponentRoutingGeneratorUrlGeneratorInterface

Holds the URL generator.

getLocales()

Gets the available locales.

Returns:array the available locales
initChildren()

Initializes the children of the data entries.

getLocaleLabels($crud)

Gets a map with localized entity labels from the CRUD YML.

Parameters:
  • $crud (array) – the CRUD entity map
Returns:

array the map with localized entity labels

configureDefinition(EntityDefinition $definition, $crud)

Configures the EntityDefinition according to the given CRUD entity map.

Parameters:
  • $definition (EntityDefinition) – the definition to configure
  • $crud (array) – the CRUD entity map
createDefinition(TranslatorInterface $translator, EntityDefinitionFactoryInterface $entityDefinitionFactory, $crud, $name)

Creates and setups an EntityDefinition instance.

Parameters:
  • $translator (TranslatorInterface) – the Translator to use for some standard field labels
  • $entityDefinitionFactory (EntityDefinitionFactoryInterface) – the EntityDefinitionFactory to use
  • $crud (array) – the parsed YAML of a CRUD entity
  • $name (string) – the name of the entity
Returns:

EntityDefinition the EntityDefinition good to go

__construct($crudFile, $crudFileCachingDirectory, UrlGeneratorInterface $urlGenerator, TranslatorInterface $translator, DataFactoryInterface $dataFactory, EntityDefinitionFactoryInterface $entityDefinitionFactory, FilesystemInterface $filesystem, EntityDefinitionValidatorInterface $validator)

Initializes the instance.

Parameters:
  • $crudFile (string) – the CRUD YAML file
  • $crudFileCachingDirectory (string|null) – the writable directory to store the CRUD YAML file cache
  • $urlGenerator (UrlGeneratorInterface) – the URL generator to use
  • $translator (TranslatorInterface) – the translator to use
  • $dataFactory (DataFactoryInterface) – the data factory to use
  • $entityDefinitionFactory (EntityDefinitionFactoryInterface) – the EntityDefinitionFactory to use
  • $filesystem (FilesystemInterface) – the filesystem to use
  • $validator (EntityDefinitionValidatorInterface) – the validator to use, null if no validation required
getData($name)

Getter for the AbstractData instances.

Parameters:
  • $name (string) – the entity name of the desired Data instance
Returns:

AbstractData the AbstractData instance or null on invalid name

getEntities()

Getter for all available entity names.

Returns:string[] a list of all available entity names
getEntitiesNavBar()

Getter for the entities for the navigation bar.

Returns:string[] a list of all available entity names with their group
setTemplate($key, $template)

Sets a template to use instead of the build in ones.

Parameters:
  • $key (string) – the template key to use in this format: $section.$action.$entity $section.$action $section
  • $template (string) – the template to use for this key
getTemplate($section, $action, $entity)

Determines the Twig template to use for the given parameters depending on the existance of certain template keys set in this order:

$section.$action.$entity $section.$action $section

If nothing exists, this string is returned: “@crud/<action>.twig”

Parameters:
  • $section (string) – the section of the template, either “layout” or “template”
  • $action (string) – the current calling action like “create” or “show”
  • $entity (string) – the current calling entity
Returns:

string the best fitting template

setLocale($locale)

Sets the locale to be used.

Parameters:
  • $locale (string) – the locale to be used.
isManageI18n()

Gets whether CRUDlex manages the i18n.

Returns:bool true if so
setManageI18n($manageI18n)

Sets whether CRUDlex manages the i18n.

Parameters:
  • $manageI18n (bool) – true if so
generateURL($name, $parameters)

Generates an URL.

Parameters:
  • $name (string) – the name of the route
  • $parameters (mixed) – an array of parameters
Returns:

null|string the generated URL