repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
netgen-layouts/layouts-core | bundles/BlockManagerBundle/EventListener/SerializerListener.php | SerializerListener.onView | public function onView(GetResponseForControllerResultEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$value = $event->getControllerResult();
if (!$value instanceof AbstractValue) {
return;
}
$context = [];
if ($request->query->get('html') === 'false') {
$context['disable_html'] = true;
}
$response = new JsonResponse(null, $value->getStatusCode());
$response->setContent(
$this->serializer->serialize($value, 'json', $context)
);
$event->setResponse($response);
} | php | public function onView(GetResponseForControllerResultEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$value = $event->getControllerResult();
if (!$value instanceof AbstractValue) {
return;
}
$context = [];
if ($request->query->get('html') === 'false') {
$context['disable_html'] = true;
}
$response = new JsonResponse(null, $value->getStatusCode());
$response->setContent(
$this->serializer->serialize($value, 'json', $context)
);
$event->setResponse($response);
} | [
"public",
"function",
"onView",
"(",
"GetResponseForControllerResultEvent",
"$",
"event",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";",
"$",
"value",
"=",
"$",
"event",
"->",
"getControllerResult",
"(",
")",
";",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"AbstractValue",
")",
"{",
"return",
";",
"}",
"$",
"context",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'html'",
")",
"===",
"'false'",
")",
"{",
"$",
"context",
"[",
"'disable_html'",
"]",
"=",
"true",
";",
"}",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"null",
",",
"$",
"value",
"->",
"getStatusCode",
"(",
")",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"value",
",",
"'json'",
",",
"$",
"context",
")",
")",
";",
"$",
"event",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Serializes the value provided by the event. | [
"Serializes",
"the",
"value",
"provided",
"by",
"the",
"event",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/EventListener/SerializerListener.php#L34-L57 | train |
netgen-layouts/layouts-core | lib/Parameters/ParameterBuilder.php | ParameterBuilder.buildParameterDefinition | private function buildParameterDefinition(ParameterBuilderInterface $builder): ParameterDefinition
{
$data = [
'name' => $builder->getName(),
'type' => $builder->getType(),
'options' => $builder->getOptions(),
'isRequired' => $builder->isRequired(),
'defaultValue' => $builder->getDefaultValue(),
'label' => $builder->getLabel(),
'groups' => $builder->getGroups(),
'constraints' => $builder->getConstraints(),
];
// We build the sub parameters in order to lock the child builders
$subParameters = $builder->buildParameterDefinitions();
if (!$builder->getType() instanceof CompoundParameterTypeInterface) {
return ParameterDefinition::fromArray($data);
}
$data['parameterDefinitions'] = $subParameters;
return CompoundParameterDefinition::fromArray($data);
} | php | private function buildParameterDefinition(ParameterBuilderInterface $builder): ParameterDefinition
{
$data = [
'name' => $builder->getName(),
'type' => $builder->getType(),
'options' => $builder->getOptions(),
'isRequired' => $builder->isRequired(),
'defaultValue' => $builder->getDefaultValue(),
'label' => $builder->getLabel(),
'groups' => $builder->getGroups(),
'constraints' => $builder->getConstraints(),
];
// We build the sub parameters in order to lock the child builders
$subParameters = $builder->buildParameterDefinitions();
if (!$builder->getType() instanceof CompoundParameterTypeInterface) {
return ParameterDefinition::fromArray($data);
}
$data['parameterDefinitions'] = $subParameters;
return CompoundParameterDefinition::fromArray($data);
} | [
"private",
"function",
"buildParameterDefinition",
"(",
"ParameterBuilderInterface",
"$",
"builder",
")",
":",
"ParameterDefinition",
"{",
"$",
"data",
"=",
"[",
"'name'",
"=>",
"$",
"builder",
"->",
"getName",
"(",
")",
",",
"'type'",
"=>",
"$",
"builder",
"->",
"getType",
"(",
")",
",",
"'options'",
"=>",
"$",
"builder",
"->",
"getOptions",
"(",
")",
",",
"'isRequired'",
"=>",
"$",
"builder",
"->",
"isRequired",
"(",
")",
",",
"'defaultValue'",
"=>",
"$",
"builder",
"->",
"getDefaultValue",
"(",
")",
",",
"'label'",
"=>",
"$",
"builder",
"->",
"getLabel",
"(",
")",
",",
"'groups'",
"=>",
"$",
"builder",
"->",
"getGroups",
"(",
")",
",",
"'constraints'",
"=>",
"$",
"builder",
"->",
"getConstraints",
"(",
")",
",",
"]",
";",
"// We build the sub parameters in order to lock the child builders",
"$",
"subParameters",
"=",
"$",
"builder",
"->",
"buildParameterDefinitions",
"(",
")",
";",
"if",
"(",
"!",
"$",
"builder",
"->",
"getType",
"(",
")",
"instanceof",
"CompoundParameterTypeInterface",
")",
"{",
"return",
"ParameterDefinition",
"::",
"fromArray",
"(",
"$",
"data",
")",
";",
"}",
"$",
"data",
"[",
"'parameterDefinitions'",
"]",
"=",
"$",
"subParameters",
";",
"return",
"CompoundParameterDefinition",
"::",
"fromArray",
"(",
"$",
"data",
")",
";",
"}"
]
| Builds the parameter definition. | [
"Builds",
"the",
"parameter",
"definition",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/ParameterBuilder.php#L340-L363 | train |
netgen-layouts/layouts-core | lib/Parameters/ParameterBuilder.php | ParameterBuilder.resolveOptions | private function resolveOptions(array $options): array
{
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefault('default_value', null);
$optionsResolver->setDefault('required', false);
$optionsResolver->setDefault('label', null);
$optionsResolver->setDefault('groups', []);
$optionsResolver->setDefault('constraints', []);
if ($this->type instanceof ParameterTypeInterface) {
$this->type->configureOptions($optionsResolver);
}
$this->configureOptions($optionsResolver);
$optionsResolver->setRequired(['required', 'default_value', 'label', 'groups', 'constraints']);
$optionsResolver->setAllowedTypes('required', 'bool');
$optionsResolver->setAllowedTypes('label', ['string', 'null', 'bool']);
$optionsResolver->setAllowedTypes('groups', 'array');
$optionsResolver->setAllowedTypes('constraints', 'array');
// @deprecated Replace with "string[]" allowed type when support for Symfony 2.8 ends
$optionsResolver->setAllowedValues(
'groups',
static function (array $groups): bool {
foreach ($groups as $group) {
if (!is_string($group)) {
return false;
}
}
return true;
}
);
$optionsResolver->setAllowedValues(
'constraints',
function (array $constraints): bool {
return $this->validateConstraints($constraints);
}
);
$optionsResolver->setNormalizer(
'groups',
function (Options $options, array $value): array {
if (!$this->parentBuilder instanceof ParameterBuilderInterface) {
return $value;
}
if (!$this->parentBuilder->getType() instanceof CompoundParameterTypeInterface) {
return $value;
}
return $this->parentBuilder->getGroups();
}
);
$optionsResolver->setAllowedValues(
'label',
static function ($value): bool {
if (!is_bool($value)) {
return true;
}
return $value === false;
}
);
$resolvedOptions = $optionsResolver->resolve($options);
$this->isRequired = $resolvedOptions['required'];
$this->defaultValue = $resolvedOptions['default_value'];
$this->label = $resolvedOptions['label'];
$this->groups = $resolvedOptions['groups'];
$this->constraints = $resolvedOptions['constraints'];
unset(
$resolvedOptions['required'],
$resolvedOptions['default_value'],
$resolvedOptions['label'],
$resolvedOptions['groups'],
$resolvedOptions['constraints']
);
return $resolvedOptions;
} | php | private function resolveOptions(array $options): array
{
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefault('default_value', null);
$optionsResolver->setDefault('required', false);
$optionsResolver->setDefault('label', null);
$optionsResolver->setDefault('groups', []);
$optionsResolver->setDefault('constraints', []);
if ($this->type instanceof ParameterTypeInterface) {
$this->type->configureOptions($optionsResolver);
}
$this->configureOptions($optionsResolver);
$optionsResolver->setRequired(['required', 'default_value', 'label', 'groups', 'constraints']);
$optionsResolver->setAllowedTypes('required', 'bool');
$optionsResolver->setAllowedTypes('label', ['string', 'null', 'bool']);
$optionsResolver->setAllowedTypes('groups', 'array');
$optionsResolver->setAllowedTypes('constraints', 'array');
// @deprecated Replace with "string[]" allowed type when support for Symfony 2.8 ends
$optionsResolver->setAllowedValues(
'groups',
static function (array $groups): bool {
foreach ($groups as $group) {
if (!is_string($group)) {
return false;
}
}
return true;
}
);
$optionsResolver->setAllowedValues(
'constraints',
function (array $constraints): bool {
return $this->validateConstraints($constraints);
}
);
$optionsResolver->setNormalizer(
'groups',
function (Options $options, array $value): array {
if (!$this->parentBuilder instanceof ParameterBuilderInterface) {
return $value;
}
if (!$this->parentBuilder->getType() instanceof CompoundParameterTypeInterface) {
return $value;
}
return $this->parentBuilder->getGroups();
}
);
$optionsResolver->setAllowedValues(
'label',
static function ($value): bool {
if (!is_bool($value)) {
return true;
}
return $value === false;
}
);
$resolvedOptions = $optionsResolver->resolve($options);
$this->isRequired = $resolvedOptions['required'];
$this->defaultValue = $resolvedOptions['default_value'];
$this->label = $resolvedOptions['label'];
$this->groups = $resolvedOptions['groups'];
$this->constraints = $resolvedOptions['constraints'];
unset(
$resolvedOptions['required'],
$resolvedOptions['default_value'],
$resolvedOptions['label'],
$resolvedOptions['groups'],
$resolvedOptions['constraints']
);
return $resolvedOptions;
} | [
"private",
"function",
"resolveOptions",
"(",
"array",
"$",
"options",
")",
":",
"array",
"{",
"$",
"optionsResolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'default_value'",
",",
"null",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'required'",
",",
"false",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'label'",
",",
"null",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'groups'",
",",
"[",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setDefault",
"(",
"'constraints'",
",",
"[",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"type",
"instanceof",
"ParameterTypeInterface",
")",
"{",
"$",
"this",
"->",
"type",
"->",
"configureOptions",
"(",
"$",
"optionsResolver",
")",
";",
"}",
"$",
"this",
"->",
"configureOptions",
"(",
"$",
"optionsResolver",
")",
";",
"$",
"optionsResolver",
"->",
"setRequired",
"(",
"[",
"'required'",
",",
"'default_value'",
",",
"'label'",
",",
"'groups'",
",",
"'constraints'",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'required'",
",",
"'bool'",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'label'",
",",
"[",
"'string'",
",",
"'null'",
",",
"'bool'",
"]",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'groups'",
",",
"'array'",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedTypes",
"(",
"'constraints'",
",",
"'array'",
")",
";",
"// @deprecated Replace with \"string[]\" allowed type when support for Symfony 2.8 ends",
"$",
"optionsResolver",
"->",
"setAllowedValues",
"(",
"'groups'",
",",
"static",
"function",
"(",
"array",
"$",
"groups",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"group",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedValues",
"(",
"'constraints'",
",",
"function",
"(",
"array",
"$",
"constraints",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"validateConstraints",
"(",
"$",
"constraints",
")",
";",
"}",
")",
";",
"$",
"optionsResolver",
"->",
"setNormalizer",
"(",
"'groups'",
",",
"function",
"(",
"Options",
"$",
"options",
",",
"array",
"$",
"value",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parentBuilder",
"instanceof",
"ParameterBuilderInterface",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"parentBuilder",
"->",
"getType",
"(",
")",
"instanceof",
"CompoundParameterTypeInterface",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"parentBuilder",
"->",
"getGroups",
"(",
")",
";",
"}",
")",
";",
"$",
"optionsResolver",
"->",
"setAllowedValues",
"(",
"'label'",
",",
"static",
"function",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"value",
"===",
"false",
";",
"}",
")",
";",
"$",
"resolvedOptions",
"=",
"$",
"optionsResolver",
"->",
"resolve",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"isRequired",
"=",
"$",
"resolvedOptions",
"[",
"'required'",
"]",
";",
"$",
"this",
"->",
"defaultValue",
"=",
"$",
"resolvedOptions",
"[",
"'default_value'",
"]",
";",
"$",
"this",
"->",
"label",
"=",
"$",
"resolvedOptions",
"[",
"'label'",
"]",
";",
"$",
"this",
"->",
"groups",
"=",
"$",
"resolvedOptions",
"[",
"'groups'",
"]",
";",
"$",
"this",
"->",
"constraints",
"=",
"$",
"resolvedOptions",
"[",
"'constraints'",
"]",
";",
"unset",
"(",
"$",
"resolvedOptions",
"[",
"'required'",
"]",
",",
"$",
"resolvedOptions",
"[",
"'default_value'",
"]",
",",
"$",
"resolvedOptions",
"[",
"'label'",
"]",
",",
"$",
"resolvedOptions",
"[",
"'groups'",
"]",
",",
"$",
"resolvedOptions",
"[",
"'constraints'",
"]",
")",
";",
"return",
"$",
"resolvedOptions",
";",
"}"
]
| Resolves the parameter options. | [
"Resolves",
"the",
"parameter",
"options",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/ParameterBuilder.php#L368-L455 | train |
netgen-layouts/layouts-core | lib/Parameters/ParameterBuilder.php | ParameterBuilder.validateConstraints | private function validateConstraints(array $constraints): bool
{
foreach ($constraints as $constraint) {
if (!$constraint instanceof Closure && !$constraint instanceof Constraint) {
return false;
}
}
return true;
} | php | private function validateConstraints(array $constraints): bool
{
foreach ($constraints as $constraint) {
if (!$constraint instanceof Closure && !$constraint instanceof Constraint) {
return false;
}
}
return true;
} | [
"private",
"function",
"validateConstraints",
"(",
"array",
"$",
"constraints",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"constraints",
"as",
"$",
"constraint",
")",
"{",
"if",
"(",
"!",
"$",
"constraint",
"instanceof",
"Closure",
"&&",
"!",
"$",
"constraint",
"instanceof",
"Constraint",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Validates the list of constraints to be either a Symfony constraint or a closure. | [
"Validates",
"the",
"list",
"of",
"constraints",
"to",
"be",
"either",
"a",
"Symfony",
"constraint",
"or",
"a",
"closure",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/ParameterBuilder.php#L460-L469 | train |
netgen-layouts/layouts-core | lib/Utils/Hydrator.php | Hydrator.extract | public function extract($object): array
{
if (!is_object($object)) {
throw new RuntimeException(
sprintf('%s expects the provided $object to be a PHP object', __METHOD__)
);
}
return (function (): array {
return get_object_vars($this);
})->call($object);
} | php | public function extract($object): array
{
if (!is_object($object)) {
throw new RuntimeException(
sprintf('%s expects the provided $object to be a PHP object', __METHOD__)
);
}
return (function (): array {
return get_object_vars($this);
})->call($object);
} | [
"public",
"function",
"extract",
"(",
"$",
"object",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'%s expects the provided $object to be a PHP object'",
",",
"__METHOD__",
")",
")",
";",
"}",
"return",
"(",
"function",
"(",
")",
":",
"array",
"{",
"return",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"}",
")",
"->",
"call",
"(",
"$",
"object",
")",
";",
"}"
]
| Extract values from an object.
@param object $object
@return array<string, mixed> | [
"Extract",
"values",
"from",
"an",
"object",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Utils/Hydrator.php#L18-L29 | train |
netgen-layouts/layouts-core | lib/Core/Service/BlockService.php | BlockService.filterUntranslatedBlocks | private function filterUntranslatedBlocks(iterable $blocks, ?array $locales, bool $useMainLocale): Generator
{
foreach ($blocks as $block) {
try {
yield $this->mapper->mapBlock($block, $locales, $useMainLocale);
} catch (NotFoundException $e) {
// Block does not have the translation, skip it
}
}
} | php | private function filterUntranslatedBlocks(iterable $blocks, ?array $locales, bool $useMainLocale): Generator
{
foreach ($blocks as $block) {
try {
yield $this->mapper->mapBlock($block, $locales, $useMainLocale);
} catch (NotFoundException $e) {
// Block does not have the translation, skip it
}
}
} | [
"private",
"function",
"filterUntranslatedBlocks",
"(",
"iterable",
"$",
"blocks",
",",
"?",
"array",
"$",
"locales",
",",
"bool",
"$",
"useMainLocale",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"block",
")",
"{",
"try",
"{",
"yield",
"$",
"this",
"->",
"mapper",
"->",
"mapBlock",
"(",
"$",
"block",
",",
"$",
"locales",
",",
"$",
"useMainLocale",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"// Block does not have the translation, skip it",
"}",
"}",
"}"
]
| Returns all blocks from provided input, with all untranslated blocks filtered out. | [
"Returns",
"all",
"blocks",
"from",
"provided",
"input",
"with",
"all",
"untranslated",
"blocks",
"filtered",
"out",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Service/BlockService.php#L594-L603 | train |
netgen-layouts/layouts-core | lib/Core/Service/BlockService.php | BlockService.internalCreateBlock | private function internalCreateBlock(
APIBlockCreateStruct $blockCreateStruct,
PersistenceBlock $targetBlock,
string $placeholder,
?int $position = null
): Block {
$persistenceLayout = $this->layoutHandler->loadLayout($targetBlock->layoutId, Value::STATUS_DRAFT);
$createdBlock = $this->transaction(
function () use ($blockCreateStruct, $persistenceLayout, $targetBlock, $placeholder, $position): PersistenceBlock {
$blockDefinition = $blockCreateStruct->getDefinition();
$createdBlock = $this->blockHandler->createBlock(
BlockCreateStruct::fromArray(
[
'status' => $targetBlock->status,
'position' => $position,
'definitionIdentifier' => $blockDefinition->getIdentifier(),
'viewType' => $blockCreateStruct->viewType,
'itemViewType' => $blockCreateStruct->itemViewType,
'name' => $blockCreateStruct->name,
'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
'isTranslatable' => $blockCreateStruct->isTranslatable,
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$blockDefinition,
$blockCreateStruct->getParameterValues()
)
),
'config' => iterator_to_array(
$this->configMapper->serializeValues(
$blockCreateStruct->getConfigStructs(),
$blockDefinition->getConfigDefinitions()
)
),
]
),
$persistenceLayout,
$targetBlock,
$placeholder
);
$collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
if (count($collectionCreateStructs) > 0) {
foreach ($collectionCreateStructs as $identifier => $collectionCreateStruct) {
$createdCollection = $this->collectionHandler->createCollection(
CollectionCreateStruct::fromArray(
[
'status' => Value::STATUS_DRAFT,
'offset' => $collectionCreateStruct->offset,
'limit' => $collectionCreateStruct->limit,
'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
'isTranslatable' => $blockCreateStruct->isTranslatable,
'mainLocale' => $persistenceLayout->mainLocale,
]
)
);
if ($collectionCreateStruct->queryCreateStruct instanceof APIQueryCreateStruct) {
$queryType = $collectionCreateStruct->queryCreateStruct->getQueryType();
$this->collectionHandler->createQuery(
$createdCollection,
QueryCreateStruct::fromArray(
[
'type' => $queryType->getType(),
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$queryType,
$collectionCreateStruct->queryCreateStruct->getParameterValues()
)
),
]
)
);
}
if ($blockCreateStruct->isTranslatable) {
foreach ($persistenceLayout->availableLocales as $locale) {
if ($locale !== $persistenceLayout->mainLocale) {
$createdCollection = $this->collectionHandler->createCollectionTranslation(
$createdCollection,
$locale,
$createdCollection->mainLocale
);
}
}
}
$this->blockHandler->createCollectionReference(
$createdBlock,
$createdCollection,
(string) $identifier
);
}
}
return $createdBlock;
}
);
return $this->mapper->mapBlock($createdBlock);
} | php | private function internalCreateBlock(
APIBlockCreateStruct $blockCreateStruct,
PersistenceBlock $targetBlock,
string $placeholder,
?int $position = null
): Block {
$persistenceLayout = $this->layoutHandler->loadLayout($targetBlock->layoutId, Value::STATUS_DRAFT);
$createdBlock = $this->transaction(
function () use ($blockCreateStruct, $persistenceLayout, $targetBlock, $placeholder, $position): PersistenceBlock {
$blockDefinition = $blockCreateStruct->getDefinition();
$createdBlock = $this->blockHandler->createBlock(
BlockCreateStruct::fromArray(
[
'status' => $targetBlock->status,
'position' => $position,
'definitionIdentifier' => $blockDefinition->getIdentifier(),
'viewType' => $blockCreateStruct->viewType,
'itemViewType' => $blockCreateStruct->itemViewType,
'name' => $blockCreateStruct->name,
'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
'isTranslatable' => $blockCreateStruct->isTranslatable,
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$blockDefinition,
$blockCreateStruct->getParameterValues()
)
),
'config' => iterator_to_array(
$this->configMapper->serializeValues(
$blockCreateStruct->getConfigStructs(),
$blockDefinition->getConfigDefinitions()
)
),
]
),
$persistenceLayout,
$targetBlock,
$placeholder
);
$collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
if (count($collectionCreateStructs) > 0) {
foreach ($collectionCreateStructs as $identifier => $collectionCreateStruct) {
$createdCollection = $this->collectionHandler->createCollection(
CollectionCreateStruct::fromArray(
[
'status' => Value::STATUS_DRAFT,
'offset' => $collectionCreateStruct->offset,
'limit' => $collectionCreateStruct->limit,
'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
'isTranslatable' => $blockCreateStruct->isTranslatable,
'mainLocale' => $persistenceLayout->mainLocale,
]
)
);
if ($collectionCreateStruct->queryCreateStruct instanceof APIQueryCreateStruct) {
$queryType = $collectionCreateStruct->queryCreateStruct->getQueryType();
$this->collectionHandler->createQuery(
$createdCollection,
QueryCreateStruct::fromArray(
[
'type' => $queryType->getType(),
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$queryType,
$collectionCreateStruct->queryCreateStruct->getParameterValues()
)
),
]
)
);
}
if ($blockCreateStruct->isTranslatable) {
foreach ($persistenceLayout->availableLocales as $locale) {
if ($locale !== $persistenceLayout->mainLocale) {
$createdCollection = $this->collectionHandler->createCollectionTranslation(
$createdCollection,
$locale,
$createdCollection->mainLocale
);
}
}
}
$this->blockHandler->createCollectionReference(
$createdBlock,
$createdCollection,
(string) $identifier
);
}
}
return $createdBlock;
}
);
return $this->mapper->mapBlock($createdBlock);
} | [
"private",
"function",
"internalCreateBlock",
"(",
"APIBlockCreateStruct",
"$",
"blockCreateStruct",
",",
"PersistenceBlock",
"$",
"targetBlock",
",",
"string",
"$",
"placeholder",
",",
"?",
"int",
"$",
"position",
"=",
"null",
")",
":",
"Block",
"{",
"$",
"persistenceLayout",
"=",
"$",
"this",
"->",
"layoutHandler",
"->",
"loadLayout",
"(",
"$",
"targetBlock",
"->",
"layoutId",
",",
"Value",
"::",
"STATUS_DRAFT",
")",
";",
"$",
"createdBlock",
"=",
"$",
"this",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"blockCreateStruct",
",",
"$",
"persistenceLayout",
",",
"$",
"targetBlock",
",",
"$",
"placeholder",
",",
"$",
"position",
")",
":",
"PersistenceBlock",
"{",
"$",
"blockDefinition",
"=",
"$",
"blockCreateStruct",
"->",
"getDefinition",
"(",
")",
";",
"$",
"createdBlock",
"=",
"$",
"this",
"->",
"blockHandler",
"->",
"createBlock",
"(",
"BlockCreateStruct",
"::",
"fromArray",
"(",
"[",
"'status'",
"=>",
"$",
"targetBlock",
"->",
"status",
",",
"'position'",
"=>",
"$",
"position",
",",
"'definitionIdentifier'",
"=>",
"$",
"blockDefinition",
"->",
"getIdentifier",
"(",
")",
",",
"'viewType'",
"=>",
"$",
"blockCreateStruct",
"->",
"viewType",
",",
"'itemViewType'",
"=>",
"$",
"blockCreateStruct",
"->",
"itemViewType",
",",
"'name'",
"=>",
"$",
"blockCreateStruct",
"->",
"name",
",",
"'alwaysAvailable'",
"=>",
"$",
"blockCreateStruct",
"->",
"alwaysAvailable",
",",
"'isTranslatable'",
"=>",
"$",
"blockCreateStruct",
"->",
"isTranslatable",
",",
"'parameters'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"serializeValues",
"(",
"$",
"blockDefinition",
",",
"$",
"blockCreateStruct",
"->",
"getParameterValues",
"(",
")",
")",
")",
",",
"'config'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"configMapper",
"->",
"serializeValues",
"(",
"$",
"blockCreateStruct",
"->",
"getConfigStructs",
"(",
")",
",",
"$",
"blockDefinition",
"->",
"getConfigDefinitions",
"(",
")",
")",
")",
",",
"]",
")",
",",
"$",
"persistenceLayout",
",",
"$",
"targetBlock",
",",
"$",
"placeholder",
")",
";",
"$",
"collectionCreateStructs",
"=",
"$",
"blockCreateStruct",
"->",
"getCollectionCreateStructs",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"collectionCreateStructs",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"collectionCreateStructs",
"as",
"$",
"identifier",
"=>",
"$",
"collectionCreateStruct",
")",
"{",
"$",
"createdCollection",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"createCollection",
"(",
"CollectionCreateStruct",
"::",
"fromArray",
"(",
"[",
"'status'",
"=>",
"Value",
"::",
"STATUS_DRAFT",
",",
"'offset'",
"=>",
"$",
"collectionCreateStruct",
"->",
"offset",
",",
"'limit'",
"=>",
"$",
"collectionCreateStruct",
"->",
"limit",
",",
"'alwaysAvailable'",
"=>",
"$",
"blockCreateStruct",
"->",
"alwaysAvailable",
",",
"'isTranslatable'",
"=>",
"$",
"blockCreateStruct",
"->",
"isTranslatable",
",",
"'mainLocale'",
"=>",
"$",
"persistenceLayout",
"->",
"mainLocale",
",",
"]",
")",
")",
";",
"if",
"(",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
"instanceof",
"APIQueryCreateStruct",
")",
"{",
"$",
"queryType",
"=",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
"->",
"getQueryType",
"(",
")",
";",
"$",
"this",
"->",
"collectionHandler",
"->",
"createQuery",
"(",
"$",
"createdCollection",
",",
"QueryCreateStruct",
"::",
"fromArray",
"(",
"[",
"'type'",
"=>",
"$",
"queryType",
"->",
"getType",
"(",
")",
",",
"'parameters'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"serializeValues",
"(",
"$",
"queryType",
",",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
"->",
"getParameterValues",
"(",
")",
")",
")",
",",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"blockCreateStruct",
"->",
"isTranslatable",
")",
"{",
"foreach",
"(",
"$",
"persistenceLayout",
"->",
"availableLocales",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"locale",
"!==",
"$",
"persistenceLayout",
"->",
"mainLocale",
")",
"{",
"$",
"createdCollection",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"createCollectionTranslation",
"(",
"$",
"createdCollection",
",",
"$",
"locale",
",",
"$",
"createdCollection",
"->",
"mainLocale",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"blockHandler",
"->",
"createCollectionReference",
"(",
"$",
"createdBlock",
",",
"$",
"createdCollection",
",",
"(",
"string",
")",
"$",
"identifier",
")",
";",
"}",
"}",
"return",
"$",
"createdBlock",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"mapper",
"->",
"mapBlock",
"(",
"$",
"createdBlock",
")",
";",
"}"
]
| Creates a block at specified target block and placeholder and position.
If position is not provided, block is placed at the end of the placeholder.
This is an internal method unifying creating a block in a zone and a parent block. | [
"Creates",
"a",
"block",
"at",
"specified",
"target",
"block",
"and",
"placeholder",
"and",
"position",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Service/BlockService.php#L612-L713 | train |
netgen-layouts/layouts-core | lib/Core/Service/BlockService.php | BlockService.internalMoveBlock | private function internalMoveBlock(PersistenceBlock $block, PersistenceBlock $targetBlock, string $placeholder, int $position): PersistenceBlock
{
return $this->transaction(
function () use ($block, $targetBlock, $placeholder, $position): PersistenceBlock {
if ($block->parentId === $targetBlock->id && $block->placeholder === $placeholder) {
return $this->blockHandler->moveBlockToPosition($block, $position);
}
return $this->blockHandler->moveBlock(
$block,
$targetBlock,
$placeholder,
$position
);
}
);
} | php | private function internalMoveBlock(PersistenceBlock $block, PersistenceBlock $targetBlock, string $placeholder, int $position): PersistenceBlock
{
return $this->transaction(
function () use ($block, $targetBlock, $placeholder, $position): PersistenceBlock {
if ($block->parentId === $targetBlock->id && $block->placeholder === $placeholder) {
return $this->blockHandler->moveBlockToPosition($block, $position);
}
return $this->blockHandler->moveBlock(
$block,
$targetBlock,
$placeholder,
$position
);
}
);
} | [
"private",
"function",
"internalMoveBlock",
"(",
"PersistenceBlock",
"$",
"block",
",",
"PersistenceBlock",
"$",
"targetBlock",
",",
"string",
"$",
"placeholder",
",",
"int",
"$",
"position",
")",
":",
"PersistenceBlock",
"{",
"return",
"$",
"this",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"block",
",",
"$",
"targetBlock",
",",
"$",
"placeholder",
",",
"$",
"position",
")",
":",
"PersistenceBlock",
"{",
"if",
"(",
"$",
"block",
"->",
"parentId",
"===",
"$",
"targetBlock",
"->",
"id",
"&&",
"$",
"block",
"->",
"placeholder",
"===",
"$",
"placeholder",
")",
"{",
"return",
"$",
"this",
"->",
"blockHandler",
"->",
"moveBlockToPosition",
"(",
"$",
"block",
",",
"$",
"position",
")",
";",
"}",
"return",
"$",
"this",
"->",
"blockHandler",
"->",
"moveBlock",
"(",
"$",
"block",
",",
"$",
"targetBlock",
",",
"$",
"placeholder",
",",
"$",
"position",
")",
";",
"}",
")",
";",
"}"
]
| Moves a block to specified target block and placeholder and position.
This is an internal method unifying moving a block to a zone and to a parent block. | [
"Moves",
"a",
"block",
"to",
"specified",
"target",
"block",
"and",
"placeholder",
"and",
"position",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Service/BlockService.php#L720-L736 | train |
netgen-layouts/layouts-core | lib/Core/Service/BlockService.php | BlockService.internalDisableTranslations | private function internalDisableTranslations(PersistenceBlock $block): PersistenceBlock
{
$block = $this->blockHandler->updateBlock(
$block,
BlockUpdateStruct::fromArray(
[
'isTranslatable' => false,
]
)
);
foreach ($block->availableLocales as $locale) {
if ($locale !== $block->mainLocale) {
$block = $this->blockHandler->deleteBlockTranslation(
$block,
$locale
);
}
}
foreach ($this->blockHandler->loadChildBlocks($block) as $childBlock) {
$this->internalDisableTranslations($childBlock);
}
return $block;
} | php | private function internalDisableTranslations(PersistenceBlock $block): PersistenceBlock
{
$block = $this->blockHandler->updateBlock(
$block,
BlockUpdateStruct::fromArray(
[
'isTranslatable' => false,
]
)
);
foreach ($block->availableLocales as $locale) {
if ($locale !== $block->mainLocale) {
$block = $this->blockHandler->deleteBlockTranslation(
$block,
$locale
);
}
}
foreach ($this->blockHandler->loadChildBlocks($block) as $childBlock) {
$this->internalDisableTranslations($childBlock);
}
return $block;
} | [
"private",
"function",
"internalDisableTranslations",
"(",
"PersistenceBlock",
"$",
"block",
")",
":",
"PersistenceBlock",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"blockHandler",
"->",
"updateBlock",
"(",
"$",
"block",
",",
"BlockUpdateStruct",
"::",
"fromArray",
"(",
"[",
"'isTranslatable'",
"=>",
"false",
",",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"block",
"->",
"availableLocales",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"locale",
"!==",
"$",
"block",
"->",
"mainLocale",
")",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"blockHandler",
"->",
"deleteBlockTranslation",
"(",
"$",
"block",
",",
"$",
"locale",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"blockHandler",
"->",
"loadChildBlocks",
"(",
"$",
"block",
")",
"as",
"$",
"childBlock",
")",
"{",
"$",
"this",
"->",
"internalDisableTranslations",
"(",
"$",
"childBlock",
")",
";",
"}",
"return",
"$",
"block",
";",
"}"
]
| Disables the translations on provided block and removes all translations
keeping only the main one. | [
"Disables",
"the",
"translations",
"on",
"provided",
"block",
"and",
"removes",
"all",
"translations",
"keeping",
"only",
"the",
"main",
"one",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Service/BlockService.php#L742-L767 | train |
netgen-layouts/layouts-core | lib/Core/Service/BlockService.php | BlockService.updateBlockTranslations | private function updateBlockTranslations(
BlockDefinitionInterface $blockDefinition,
PersistenceBlock $persistenceBlock,
APIBlockUpdateStruct $blockUpdateStruct
): PersistenceBlock {
if ($blockUpdateStruct->locale === $persistenceBlock->mainLocale) {
$persistenceBlock = $this->blockHandler->updateBlockTranslation(
$persistenceBlock,
$blockUpdateStruct->locale,
BlockTranslationUpdateStruct::fromArray(
[
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$blockDefinition,
$blockUpdateStruct->getParameterValues(),
$persistenceBlock->parameters[$persistenceBlock->mainLocale]
)
),
]
)
);
}
$untranslatableParams = iterator_to_array(
$this->parameterMapper->extractUntranslatableParameters(
$blockDefinition,
$persistenceBlock->parameters[$persistenceBlock->mainLocale]
)
);
$localesToUpdate = [$blockUpdateStruct->locale];
if ($persistenceBlock->mainLocale === $blockUpdateStruct->locale) {
$localesToUpdate = $persistenceBlock->availableLocales;
// Remove the main locale from the array, since we already updated that one
$mainLocaleOffset = array_search($persistenceBlock->mainLocale, $persistenceBlock->availableLocales, true);
if (is_int($mainLocaleOffset)) {
array_splice($localesToUpdate, $mainLocaleOffset, 1);
}
}
foreach ($localesToUpdate as $locale) {
$params = $persistenceBlock->parameters[$locale];
if ($locale === $blockUpdateStruct->locale) {
$params = iterator_to_array(
$this->parameterMapper->serializeValues(
$blockDefinition,
$blockUpdateStruct->getParameterValues(),
$params
)
);
}
$persistenceBlock = $this->blockHandler->updateBlockTranslation(
$persistenceBlock,
$locale,
BlockTranslationUpdateStruct::fromArray(
[
'parameters' => $untranslatableParams + $params,
]
)
);
}
return $persistenceBlock;
} | php | private function updateBlockTranslations(
BlockDefinitionInterface $blockDefinition,
PersistenceBlock $persistenceBlock,
APIBlockUpdateStruct $blockUpdateStruct
): PersistenceBlock {
if ($blockUpdateStruct->locale === $persistenceBlock->mainLocale) {
$persistenceBlock = $this->blockHandler->updateBlockTranslation(
$persistenceBlock,
$blockUpdateStruct->locale,
BlockTranslationUpdateStruct::fromArray(
[
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$blockDefinition,
$blockUpdateStruct->getParameterValues(),
$persistenceBlock->parameters[$persistenceBlock->mainLocale]
)
),
]
)
);
}
$untranslatableParams = iterator_to_array(
$this->parameterMapper->extractUntranslatableParameters(
$blockDefinition,
$persistenceBlock->parameters[$persistenceBlock->mainLocale]
)
);
$localesToUpdate = [$blockUpdateStruct->locale];
if ($persistenceBlock->mainLocale === $blockUpdateStruct->locale) {
$localesToUpdate = $persistenceBlock->availableLocales;
// Remove the main locale from the array, since we already updated that one
$mainLocaleOffset = array_search($persistenceBlock->mainLocale, $persistenceBlock->availableLocales, true);
if (is_int($mainLocaleOffset)) {
array_splice($localesToUpdate, $mainLocaleOffset, 1);
}
}
foreach ($localesToUpdate as $locale) {
$params = $persistenceBlock->parameters[$locale];
if ($locale === $blockUpdateStruct->locale) {
$params = iterator_to_array(
$this->parameterMapper->serializeValues(
$blockDefinition,
$blockUpdateStruct->getParameterValues(),
$params
)
);
}
$persistenceBlock = $this->blockHandler->updateBlockTranslation(
$persistenceBlock,
$locale,
BlockTranslationUpdateStruct::fromArray(
[
'parameters' => $untranslatableParams + $params,
]
)
);
}
return $persistenceBlock;
} | [
"private",
"function",
"updateBlockTranslations",
"(",
"BlockDefinitionInterface",
"$",
"blockDefinition",
",",
"PersistenceBlock",
"$",
"persistenceBlock",
",",
"APIBlockUpdateStruct",
"$",
"blockUpdateStruct",
")",
":",
"PersistenceBlock",
"{",
"if",
"(",
"$",
"blockUpdateStruct",
"->",
"locale",
"===",
"$",
"persistenceBlock",
"->",
"mainLocale",
")",
"{",
"$",
"persistenceBlock",
"=",
"$",
"this",
"->",
"blockHandler",
"->",
"updateBlockTranslation",
"(",
"$",
"persistenceBlock",
",",
"$",
"blockUpdateStruct",
"->",
"locale",
",",
"BlockTranslationUpdateStruct",
"::",
"fromArray",
"(",
"[",
"'parameters'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"serializeValues",
"(",
"$",
"blockDefinition",
",",
"$",
"blockUpdateStruct",
"->",
"getParameterValues",
"(",
")",
",",
"$",
"persistenceBlock",
"->",
"parameters",
"[",
"$",
"persistenceBlock",
"->",
"mainLocale",
"]",
")",
")",
",",
"]",
")",
")",
";",
"}",
"$",
"untranslatableParams",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"extractUntranslatableParameters",
"(",
"$",
"blockDefinition",
",",
"$",
"persistenceBlock",
"->",
"parameters",
"[",
"$",
"persistenceBlock",
"->",
"mainLocale",
"]",
")",
")",
";",
"$",
"localesToUpdate",
"=",
"[",
"$",
"blockUpdateStruct",
"->",
"locale",
"]",
";",
"if",
"(",
"$",
"persistenceBlock",
"->",
"mainLocale",
"===",
"$",
"blockUpdateStruct",
"->",
"locale",
")",
"{",
"$",
"localesToUpdate",
"=",
"$",
"persistenceBlock",
"->",
"availableLocales",
";",
"// Remove the main locale from the array, since we already updated that one",
"$",
"mainLocaleOffset",
"=",
"array_search",
"(",
"$",
"persistenceBlock",
"->",
"mainLocale",
",",
"$",
"persistenceBlock",
"->",
"availableLocales",
",",
"true",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"mainLocaleOffset",
")",
")",
"{",
"array_splice",
"(",
"$",
"localesToUpdate",
",",
"$",
"mainLocaleOffset",
",",
"1",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"localesToUpdate",
"as",
"$",
"locale",
")",
"{",
"$",
"params",
"=",
"$",
"persistenceBlock",
"->",
"parameters",
"[",
"$",
"locale",
"]",
";",
"if",
"(",
"$",
"locale",
"===",
"$",
"blockUpdateStruct",
"->",
"locale",
")",
"{",
"$",
"params",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"serializeValues",
"(",
"$",
"blockDefinition",
",",
"$",
"blockUpdateStruct",
"->",
"getParameterValues",
"(",
")",
",",
"$",
"params",
")",
")",
";",
"}",
"$",
"persistenceBlock",
"=",
"$",
"this",
"->",
"blockHandler",
"->",
"updateBlockTranslation",
"(",
"$",
"persistenceBlock",
",",
"$",
"locale",
",",
"BlockTranslationUpdateStruct",
"::",
"fromArray",
"(",
"[",
"'parameters'",
"=>",
"$",
"untranslatableParams",
"+",
"$",
"params",
",",
"]",
")",
")",
";",
"}",
"return",
"$",
"persistenceBlock",
";",
"}"
]
| Updates translations for specified block.
This makes sure that untranslatable parameters are always kept in sync between all
available translations in the block. This means that if main translation is updated,
all other translations need to be updated too to reflect changes to untranslatable params,
and if any other translation is updated, it needs to take values of untranslatable params
from the main translation. | [
"Updates",
"translations",
"for",
"specified",
"block",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Service/BlockService.php#L778-L844 | train |
netgen-layouts/layouts-core | lib/Core/Mapper/CollectionMapper.php | CollectionMapper.mapCollection | public function mapCollection(PersistenceCollection $collection, ?array $locales = null, bool $useMainLocale = true): Collection
{
$locales = is_array($locales) && count($locales) > 0 ? $locales : [$collection->mainLocale];
if ($useMainLocale && $collection->alwaysAvailable) {
$locales[] = $collection->mainLocale;
}
$validLocales = array_unique(array_intersect($locales, $collection->availableLocales));
if (count($validLocales) === 0) {
throw new NotFoundException('collection', $collection->id);
}
$collectionData = [
'id' => $collection->id,
'status' => $collection->status,
'offset' => $collection->offset,
'limit' => $collection->limit,
'items' => new LazyCollection(
function () use ($collection): array {
return array_map(
function (PersistenceItem $item): Item {
return $this->mapItem($item);
},
$this->collectionHandler->loadCollectionItems($collection)
);
}
),
'query' => function () use ($collection, $locales): ?Query {
try {
$persistenceQuery = $this->collectionHandler->loadCollectionQuery($collection);
} catch (NotFoundException $e) {
return null;
}
return $this->mapQuery($persistenceQuery, $locales, false);
},
'isTranslatable' => $collection->isTranslatable,
'mainLocale' => $collection->mainLocale,
'alwaysAvailable' => $collection->alwaysAvailable,
'availableLocales' => $collection->availableLocales,
'locale' => array_values($validLocales)[0],
];
return Collection::fromArray($collectionData);
} | php | public function mapCollection(PersistenceCollection $collection, ?array $locales = null, bool $useMainLocale = true): Collection
{
$locales = is_array($locales) && count($locales) > 0 ? $locales : [$collection->mainLocale];
if ($useMainLocale && $collection->alwaysAvailable) {
$locales[] = $collection->mainLocale;
}
$validLocales = array_unique(array_intersect($locales, $collection->availableLocales));
if (count($validLocales) === 0) {
throw new NotFoundException('collection', $collection->id);
}
$collectionData = [
'id' => $collection->id,
'status' => $collection->status,
'offset' => $collection->offset,
'limit' => $collection->limit,
'items' => new LazyCollection(
function () use ($collection): array {
return array_map(
function (PersistenceItem $item): Item {
return $this->mapItem($item);
},
$this->collectionHandler->loadCollectionItems($collection)
);
}
),
'query' => function () use ($collection, $locales): ?Query {
try {
$persistenceQuery = $this->collectionHandler->loadCollectionQuery($collection);
} catch (NotFoundException $e) {
return null;
}
return $this->mapQuery($persistenceQuery, $locales, false);
},
'isTranslatable' => $collection->isTranslatable,
'mainLocale' => $collection->mainLocale,
'alwaysAvailable' => $collection->alwaysAvailable,
'availableLocales' => $collection->availableLocales,
'locale' => array_values($validLocales)[0],
];
return Collection::fromArray($collectionData);
} | [
"public",
"function",
"mapCollection",
"(",
"PersistenceCollection",
"$",
"collection",
",",
"?",
"array",
"$",
"locales",
"=",
"null",
",",
"bool",
"$",
"useMainLocale",
"=",
"true",
")",
":",
"Collection",
"{",
"$",
"locales",
"=",
"is_array",
"(",
"$",
"locales",
")",
"&&",
"count",
"(",
"$",
"locales",
")",
">",
"0",
"?",
"$",
"locales",
":",
"[",
"$",
"collection",
"->",
"mainLocale",
"]",
";",
"if",
"(",
"$",
"useMainLocale",
"&&",
"$",
"collection",
"->",
"alwaysAvailable",
")",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"collection",
"->",
"mainLocale",
";",
"}",
"$",
"validLocales",
"=",
"array_unique",
"(",
"array_intersect",
"(",
"$",
"locales",
",",
"$",
"collection",
"->",
"availableLocales",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"validLocales",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'collection'",
",",
"$",
"collection",
"->",
"id",
")",
";",
"}",
"$",
"collectionData",
"=",
"[",
"'id'",
"=>",
"$",
"collection",
"->",
"id",
",",
"'status'",
"=>",
"$",
"collection",
"->",
"status",
",",
"'offset'",
"=>",
"$",
"collection",
"->",
"offset",
",",
"'limit'",
"=>",
"$",
"collection",
"->",
"limit",
",",
"'items'",
"=>",
"new",
"LazyCollection",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"collection",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"PersistenceItem",
"$",
"item",
")",
":",
"Item",
"{",
"return",
"$",
"this",
"->",
"mapItem",
"(",
"$",
"item",
")",
";",
"}",
",",
"$",
"this",
"->",
"collectionHandler",
"->",
"loadCollectionItems",
"(",
"$",
"collection",
")",
")",
";",
"}",
")",
",",
"'query'",
"=>",
"function",
"(",
")",
"use",
"(",
"$",
"collection",
",",
"$",
"locales",
")",
":",
"?",
"Query",
"{",
"try",
"{",
"$",
"persistenceQuery",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"loadCollectionQuery",
"(",
"$",
"collection",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"mapQuery",
"(",
"$",
"persistenceQuery",
",",
"$",
"locales",
",",
"false",
")",
";",
"}",
",",
"'isTranslatable'",
"=>",
"$",
"collection",
"->",
"isTranslatable",
",",
"'mainLocale'",
"=>",
"$",
"collection",
"->",
"mainLocale",
",",
"'alwaysAvailable'",
"=>",
"$",
"collection",
"->",
"alwaysAvailable",
",",
"'availableLocales'",
"=>",
"$",
"collection",
"->",
"availableLocales",
",",
"'locale'",
"=>",
"array_values",
"(",
"$",
"validLocales",
")",
"[",
"0",
"]",
",",
"]",
";",
"return",
"Collection",
"::",
"fromArray",
"(",
"$",
"collectionData",
")",
";",
"}"
]
| Builds the API collection value from persistence one.
If not empty, the first available locale in $locales array will be returned.
If the collection is always available and $useMainLocale is set to true,
collection in main locale will be returned if none of the locales in $locales
array are found.
@throws \Netgen\BlockManager\Exception\NotFoundException If the collection does not have any requested translations | [
"Builds",
"the",
"API",
"collection",
"value",
"from",
"persistence",
"one",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Mapper/CollectionMapper.php#L84-L128 | train |
netgen-layouts/layouts-core | lib/Core/Mapper/CollectionMapper.php | CollectionMapper.mapItem | public function mapItem(PersistenceItem $item): Item
{
try {
$itemDefinition = $this->itemDefinitionRegistry->getItemDefinition($item->valueType);
} catch (ItemDefinitionException $e) {
$itemDefinition = new NullItemDefinition($item->valueType);
}
$itemData = [
'id' => $item->id,
'status' => $item->status,
'definition' => $itemDefinition,
'collectionId' => $item->collectionId,
'position' => $item->position,
'value' => $item->value,
'configs' => iterator_to_array(
$this->configMapper->mapConfig(
$item->config,
$itemDefinition->getConfigDefinitions()
)
),
'cmsItem' => function () use ($item, $itemDefinition): CmsItemInterface {
$valueType = $itemDefinition instanceof NullItemDefinition ? 'null' : $itemDefinition->getValueType();
return $this->cmsItemLoader->load($item->value, $valueType);
},
];
return Item::fromArray($itemData);
} | php | public function mapItem(PersistenceItem $item): Item
{
try {
$itemDefinition = $this->itemDefinitionRegistry->getItemDefinition($item->valueType);
} catch (ItemDefinitionException $e) {
$itemDefinition = new NullItemDefinition($item->valueType);
}
$itemData = [
'id' => $item->id,
'status' => $item->status,
'definition' => $itemDefinition,
'collectionId' => $item->collectionId,
'position' => $item->position,
'value' => $item->value,
'configs' => iterator_to_array(
$this->configMapper->mapConfig(
$item->config,
$itemDefinition->getConfigDefinitions()
)
),
'cmsItem' => function () use ($item, $itemDefinition): CmsItemInterface {
$valueType = $itemDefinition instanceof NullItemDefinition ? 'null' : $itemDefinition->getValueType();
return $this->cmsItemLoader->load($item->value, $valueType);
},
];
return Item::fromArray($itemData);
} | [
"public",
"function",
"mapItem",
"(",
"PersistenceItem",
"$",
"item",
")",
":",
"Item",
"{",
"try",
"{",
"$",
"itemDefinition",
"=",
"$",
"this",
"->",
"itemDefinitionRegistry",
"->",
"getItemDefinition",
"(",
"$",
"item",
"->",
"valueType",
")",
";",
"}",
"catch",
"(",
"ItemDefinitionException",
"$",
"e",
")",
"{",
"$",
"itemDefinition",
"=",
"new",
"NullItemDefinition",
"(",
"$",
"item",
"->",
"valueType",
")",
";",
"}",
"$",
"itemData",
"=",
"[",
"'id'",
"=>",
"$",
"item",
"->",
"id",
",",
"'status'",
"=>",
"$",
"item",
"->",
"status",
",",
"'definition'",
"=>",
"$",
"itemDefinition",
",",
"'collectionId'",
"=>",
"$",
"item",
"->",
"collectionId",
",",
"'position'",
"=>",
"$",
"item",
"->",
"position",
",",
"'value'",
"=>",
"$",
"item",
"->",
"value",
",",
"'configs'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"configMapper",
"->",
"mapConfig",
"(",
"$",
"item",
"->",
"config",
",",
"$",
"itemDefinition",
"->",
"getConfigDefinitions",
"(",
")",
")",
")",
",",
"'cmsItem'",
"=>",
"function",
"(",
")",
"use",
"(",
"$",
"item",
",",
"$",
"itemDefinition",
")",
":",
"CmsItemInterface",
"{",
"$",
"valueType",
"=",
"$",
"itemDefinition",
"instanceof",
"NullItemDefinition",
"?",
"'null'",
":",
"$",
"itemDefinition",
"->",
"getValueType",
"(",
")",
";",
"return",
"$",
"this",
"->",
"cmsItemLoader",
"->",
"load",
"(",
"$",
"item",
"->",
"value",
",",
"$",
"valueType",
")",
";",
"}",
",",
"]",
";",
"return",
"Item",
"::",
"fromArray",
"(",
"$",
"itemData",
")",
";",
"}"
]
| Builds the API item value from persistence one. | [
"Builds",
"the",
"API",
"item",
"value",
"from",
"persistence",
"one",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Mapper/CollectionMapper.php#L133-L162 | train |
netgen-layouts/layouts-core | lib/Core/Mapper/CollectionMapper.php | CollectionMapper.mapQuery | public function mapQuery(PersistenceQuery $query, ?array $locales = null, bool $useMainLocale = true): Query
{
try {
$queryType = $this->queryTypeRegistry->getQueryType($query->type);
} catch (QueryTypeException $e) {
$queryType = new NullQueryType($query->type);
}
$locales = is_array($locales) && count($locales) > 0 ? $locales : [$query->mainLocale];
if ($useMainLocale && $query->alwaysAvailable) {
$locales[] = $query->mainLocale;
}
$validLocales = array_unique(array_intersect($locales, $query->availableLocales));
if (count($validLocales) === 0) {
throw new NotFoundException('query', $query->id);
}
/** @var string $queryLocale */
$queryLocale = array_values($validLocales)[0];
$untranslatableParams = iterator_to_array(
$this->parameterMapper->extractUntranslatableParameters(
$queryType,
$query->parameters[$query->mainLocale]
)
);
$queryData = [
'id' => $query->id,
'status' => $query->status,
'collectionId' => $query->collectionId,
'queryType' => $queryType,
'isTranslatable' => $query->isTranslatable,
'mainLocale' => $query->mainLocale,
'alwaysAvailable' => $query->alwaysAvailable,
'availableLocales' => $query->availableLocales,
'locale' => $queryLocale,
'parameters' => iterator_to_array(
$this->parameterMapper->mapParameters(
$queryType,
$untranslatableParams + $query->parameters[$queryLocale]
)
),
];
return Query::fromArray($queryData);
} | php | public function mapQuery(PersistenceQuery $query, ?array $locales = null, bool $useMainLocale = true): Query
{
try {
$queryType = $this->queryTypeRegistry->getQueryType($query->type);
} catch (QueryTypeException $e) {
$queryType = new NullQueryType($query->type);
}
$locales = is_array($locales) && count($locales) > 0 ? $locales : [$query->mainLocale];
if ($useMainLocale && $query->alwaysAvailable) {
$locales[] = $query->mainLocale;
}
$validLocales = array_unique(array_intersect($locales, $query->availableLocales));
if (count($validLocales) === 0) {
throw new NotFoundException('query', $query->id);
}
/** @var string $queryLocale */
$queryLocale = array_values($validLocales)[0];
$untranslatableParams = iterator_to_array(
$this->parameterMapper->extractUntranslatableParameters(
$queryType,
$query->parameters[$query->mainLocale]
)
);
$queryData = [
'id' => $query->id,
'status' => $query->status,
'collectionId' => $query->collectionId,
'queryType' => $queryType,
'isTranslatable' => $query->isTranslatable,
'mainLocale' => $query->mainLocale,
'alwaysAvailable' => $query->alwaysAvailable,
'availableLocales' => $query->availableLocales,
'locale' => $queryLocale,
'parameters' => iterator_to_array(
$this->parameterMapper->mapParameters(
$queryType,
$untranslatableParams + $query->parameters[$queryLocale]
)
),
];
return Query::fromArray($queryData);
} | [
"public",
"function",
"mapQuery",
"(",
"PersistenceQuery",
"$",
"query",
",",
"?",
"array",
"$",
"locales",
"=",
"null",
",",
"bool",
"$",
"useMainLocale",
"=",
"true",
")",
":",
"Query",
"{",
"try",
"{",
"$",
"queryType",
"=",
"$",
"this",
"->",
"queryTypeRegistry",
"->",
"getQueryType",
"(",
"$",
"query",
"->",
"type",
")",
";",
"}",
"catch",
"(",
"QueryTypeException",
"$",
"e",
")",
"{",
"$",
"queryType",
"=",
"new",
"NullQueryType",
"(",
"$",
"query",
"->",
"type",
")",
";",
"}",
"$",
"locales",
"=",
"is_array",
"(",
"$",
"locales",
")",
"&&",
"count",
"(",
"$",
"locales",
")",
">",
"0",
"?",
"$",
"locales",
":",
"[",
"$",
"query",
"->",
"mainLocale",
"]",
";",
"if",
"(",
"$",
"useMainLocale",
"&&",
"$",
"query",
"->",
"alwaysAvailable",
")",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"query",
"->",
"mainLocale",
";",
"}",
"$",
"validLocales",
"=",
"array_unique",
"(",
"array_intersect",
"(",
"$",
"locales",
",",
"$",
"query",
"->",
"availableLocales",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"validLocales",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'query'",
",",
"$",
"query",
"->",
"id",
")",
";",
"}",
"/** @var string $queryLocale */",
"$",
"queryLocale",
"=",
"array_values",
"(",
"$",
"validLocales",
")",
"[",
"0",
"]",
";",
"$",
"untranslatableParams",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"extractUntranslatableParameters",
"(",
"$",
"queryType",
",",
"$",
"query",
"->",
"parameters",
"[",
"$",
"query",
"->",
"mainLocale",
"]",
")",
")",
";",
"$",
"queryData",
"=",
"[",
"'id'",
"=>",
"$",
"query",
"->",
"id",
",",
"'status'",
"=>",
"$",
"query",
"->",
"status",
",",
"'collectionId'",
"=>",
"$",
"query",
"->",
"collectionId",
",",
"'queryType'",
"=>",
"$",
"queryType",
",",
"'isTranslatable'",
"=>",
"$",
"query",
"->",
"isTranslatable",
",",
"'mainLocale'",
"=>",
"$",
"query",
"->",
"mainLocale",
",",
"'alwaysAvailable'",
"=>",
"$",
"query",
"->",
"alwaysAvailable",
",",
"'availableLocales'",
"=>",
"$",
"query",
"->",
"availableLocales",
",",
"'locale'",
"=>",
"$",
"queryLocale",
",",
"'parameters'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"mapParameters",
"(",
"$",
"queryType",
",",
"$",
"untranslatableParams",
"+",
"$",
"query",
"->",
"parameters",
"[",
"$",
"queryLocale",
"]",
")",
")",
",",
"]",
";",
"return",
"Query",
"::",
"fromArray",
"(",
"$",
"queryData",
")",
";",
"}"
]
| Builds the API query value from persistence one.
If not empty, the first available locale in $locales array will be returned.
If the query is always available and $useMainLocale is set to true,
query in main locale will be returned if none of the locales in $locales
array are found.
@throws \Netgen\BlockManager\Exception\NotFoundException If the query does not have any requested locales | [
"Builds",
"the",
"API",
"query",
"value",
"from",
"persistence",
"one",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Mapper/CollectionMapper.php#L175-L221 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/EventListener/TwigExtensionsListener.php | TwigExtensionsListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event): void
{
foreach ($this->extensions as $extension) {
if (!class_exists($extension) || !is_a($extension, ExtensionInterface::class, true)) {
continue;
}
if ($this->twig->hasExtension($extension)) {
continue;
}
$this->twig->addExtension(new $extension());
}
} | php | public function onKernelRequest(GetResponseEvent $event): void
{
foreach ($this->extensions as $extension) {
if (!class_exists($extension) || !is_a($extension, ExtensionInterface::class, true)) {
continue;
}
if ($this->twig->hasExtension($extension)) {
continue;
}
$this->twig->addExtension(new $extension());
}
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"extension",
")",
"||",
"!",
"is_a",
"(",
"$",
"extension",
",",
"ExtensionInterface",
"::",
"class",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"twig",
"->",
"hasExtension",
"(",
"$",
"extension",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"twig",
"->",
"addExtension",
"(",
"new",
"$",
"extension",
"(",
")",
")",
";",
"}",
"}"
]
| Adds the Twig extensions to the environment if they don't already exist. | [
"Adds",
"the",
"Twig",
"extensions",
"to",
"the",
"environment",
"if",
"they",
"don",
"t",
"already",
"exist",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/EventListener/TwigExtensionsListener.php#L43-L56 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php | RenderingRuntime.renderItem | public function renderItem(array $context, CmsItemInterface $item, string $viewType, array $parameters = [], ?string $viewContext = null): string
{
try {
return $this->renderer->renderValue(
$item,
$this->getViewContext($context, $viewContext),
['view_type' => $viewType] + $parameters
);
} catch (Throwable $t) {
$message = sprintf(
'Error rendering an item with value "%s" and value type "%s"',
$item->getValue(),
$item->getValueType()
);
$this->errorHandler->handleError($t, $message);
}
return '';
} | php | public function renderItem(array $context, CmsItemInterface $item, string $viewType, array $parameters = [], ?string $viewContext = null): string
{
try {
return $this->renderer->renderValue(
$item,
$this->getViewContext($context, $viewContext),
['view_type' => $viewType] + $parameters
);
} catch (Throwable $t) {
$message = sprintf(
'Error rendering an item with value "%s" and value type "%s"',
$item->getValue(),
$item->getValueType()
);
$this->errorHandler->handleError($t, $message);
}
return '';
} | [
"public",
"function",
"renderItem",
"(",
"array",
"$",
"context",
",",
"CmsItemInterface",
"$",
"item",
",",
"string",
"$",
"viewType",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"?",
"string",
"$",
"viewContext",
"=",
"null",
")",
":",
"string",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"renderer",
"->",
"renderValue",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"getViewContext",
"(",
"$",
"context",
",",
"$",
"viewContext",
")",
",",
"[",
"'view_type'",
"=>",
"$",
"viewType",
"]",
"+",
"$",
"parameters",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Error rendering an item with value \"%s\" and value type \"%s\"'",
",",
"$",
"item",
"->",
"getValue",
"(",
")",
",",
"$",
"item",
"->",
"getValueType",
"(",
")",
")",
";",
"$",
"this",
"->",
"errorHandler",
"->",
"handleError",
"(",
"$",
"t",
",",
"$",
"message",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Renders the provided item. | [
"Renders",
"the",
"provided",
"item",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php#L71-L90 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php | RenderingRuntime.renderValue | public function renderValue(array $context, $value, array $parameters = [], ?string $viewContext = null): string
{
try {
return $this->renderer->renderValue(
$value,
$this->getViewContext($context, $viewContext),
$parameters
);
} catch (Throwable $t) {
$message = sprintf(
'Error rendering a value of type "%s"',
is_object($value) ? get_class($value) : gettype($value)
);
$this->errorHandler->handleError($t, $message, ['object' => $value]);
}
return '';
} | php | public function renderValue(array $context, $value, array $parameters = [], ?string $viewContext = null): string
{
try {
return $this->renderer->renderValue(
$value,
$this->getViewContext($context, $viewContext),
$parameters
);
} catch (Throwable $t) {
$message = sprintf(
'Error rendering a value of type "%s"',
is_object($value) ? get_class($value) : gettype($value)
);
$this->errorHandler->handleError($t, $message, ['object' => $value]);
}
return '';
} | [
"public",
"function",
"renderValue",
"(",
"array",
"$",
"context",
",",
"$",
"value",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"?",
"string",
"$",
"viewContext",
"=",
"null",
")",
":",
"string",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"renderer",
"->",
"renderValue",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"getViewContext",
"(",
"$",
"context",
",",
"$",
"viewContext",
")",
",",
"$",
"parameters",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Error rendering a value of type \"%s\"'",
",",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"gettype",
"(",
"$",
"value",
")",
")",
";",
"$",
"this",
"->",
"errorHandler",
"->",
"handleError",
"(",
"$",
"t",
",",
"$",
"message",
",",
"[",
"'object'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Renders the provided value.
@param array<string, mixed> $context
@param mixed $value
@param array<string, mixed> $parameters
@param string $viewContext
@return string | [
"Renders",
"the",
"provided",
"value",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php#L102-L120 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php | RenderingRuntime.displayZone | public function displayZone(Layout $layout, string $zoneIdentifier, string $viewContext, ContextualizedTwigTemplate $twigTemplate): void
{
$locales = null;
$request = $this->requestStack->getCurrentRequest();
if ($request instanceof Request) {
$locales = $this->localeProvider->getRequestLocales($request);
}
$zone = $layout->getZone($zoneIdentifier);
$linkedZone = $zone->getLinkedZone();
$blocks = $this->blockService->loadZoneBlocks(
$linkedZone instanceof Zone ? $linkedZone : $zone,
$locales
);
echo $this->renderValue(
[],
new ZoneReference($layout, $zoneIdentifier),
[
'blocks' => $blocks,
'twig_template' => $twigTemplate,
],
$viewContext
);
} | php | public function displayZone(Layout $layout, string $zoneIdentifier, string $viewContext, ContextualizedTwigTemplate $twigTemplate): void
{
$locales = null;
$request = $this->requestStack->getCurrentRequest();
if ($request instanceof Request) {
$locales = $this->localeProvider->getRequestLocales($request);
}
$zone = $layout->getZone($zoneIdentifier);
$linkedZone = $zone->getLinkedZone();
$blocks = $this->blockService->loadZoneBlocks(
$linkedZone instanceof Zone ? $linkedZone : $zone,
$locales
);
echo $this->renderValue(
[],
new ZoneReference($layout, $zoneIdentifier),
[
'blocks' => $blocks,
'twig_template' => $twigTemplate,
],
$viewContext
);
} | [
"public",
"function",
"displayZone",
"(",
"Layout",
"$",
"layout",
",",
"string",
"$",
"zoneIdentifier",
",",
"string",
"$",
"viewContext",
",",
"ContextualizedTwigTemplate",
"$",
"twigTemplate",
")",
":",
"void",
"{",
"$",
"locales",
"=",
"null",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"instanceof",
"Request",
")",
"{",
"$",
"locales",
"=",
"$",
"this",
"->",
"localeProvider",
"->",
"getRequestLocales",
"(",
"$",
"request",
")",
";",
"}",
"$",
"zone",
"=",
"$",
"layout",
"->",
"getZone",
"(",
"$",
"zoneIdentifier",
")",
";",
"$",
"linkedZone",
"=",
"$",
"zone",
"->",
"getLinkedZone",
"(",
")",
";",
"$",
"blocks",
"=",
"$",
"this",
"->",
"blockService",
"->",
"loadZoneBlocks",
"(",
"$",
"linkedZone",
"instanceof",
"Zone",
"?",
"$",
"linkedZone",
":",
"$",
"zone",
",",
"$",
"locales",
")",
";",
"echo",
"$",
"this",
"->",
"renderValue",
"(",
"[",
"]",
",",
"new",
"ZoneReference",
"(",
"$",
"layout",
",",
"$",
"zoneIdentifier",
")",
",",
"[",
"'blocks'",
"=>",
"$",
"blocks",
",",
"'twig_template'",
"=>",
"$",
"twigTemplate",
",",
"]",
",",
"$",
"viewContext",
")",
";",
"}"
]
| Displays the provided zone. | [
"Displays",
"the",
"provided",
"zone",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php#L125-L151 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php | RenderingRuntime.renderBlock | public function renderBlock(array $context, Block $block, array $parameters = [], ?string $viewContext = null): string
{
try {
return $this->renderer->renderValue(
$block,
$this->getViewContext($context, $viewContext),
[
'twig_template' => $context['twig_template'] ?? null,
] + $parameters
);
} catch (Throwable $t) {
$message = sprintf('Error rendering a block with ID "%s"', $block->getId());
$this->errorHandler->handleError($t, $message);
}
return '';
} | php | public function renderBlock(array $context, Block $block, array $parameters = [], ?string $viewContext = null): string
{
try {
return $this->renderer->renderValue(
$block,
$this->getViewContext($context, $viewContext),
[
'twig_template' => $context['twig_template'] ?? null,
] + $parameters
);
} catch (Throwable $t) {
$message = sprintf('Error rendering a block with ID "%s"', $block->getId());
$this->errorHandler->handleError($t, $message);
}
return '';
} | [
"public",
"function",
"renderBlock",
"(",
"array",
"$",
"context",
",",
"Block",
"$",
"block",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"?",
"string",
"$",
"viewContext",
"=",
"null",
")",
":",
"string",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"renderer",
"->",
"renderValue",
"(",
"$",
"block",
",",
"$",
"this",
"->",
"getViewContext",
"(",
"$",
"context",
",",
"$",
"viewContext",
")",
",",
"[",
"'twig_template'",
"=>",
"$",
"context",
"[",
"'twig_template'",
"]",
"??",
"null",
",",
"]",
"+",
"$",
"parameters",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Error rendering a block with ID \"%s\"'",
",",
"$",
"block",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"errorHandler",
"->",
"handleError",
"(",
"$",
"t",
",",
"$",
"message",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Renders the provided block. | [
"Renders",
"the",
"provided",
"block",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php#L156-L173 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php | RenderingRuntime.renderStringTemplate | public function renderStringTemplate(string $string, array $parameters = []): string
{
try {
$parameters = iterator_to_array($this->getTemplateVariables($parameters));
$environment = new Environment(new ArrayLoader());
$template = $environment->createTemplate($string);
return $environment->resolveTemplate($template)->render($parameters);
} catch (Throwable $t) {
return '';
}
} | php | public function renderStringTemplate(string $string, array $parameters = []): string
{
try {
$parameters = iterator_to_array($this->getTemplateVariables($parameters));
$environment = new Environment(new ArrayLoader());
$template = $environment->createTemplate($string);
return $environment->resolveTemplate($template)->render($parameters);
} catch (Throwable $t) {
return '';
}
} | [
"public",
"function",
"renderStringTemplate",
"(",
"string",
"$",
"string",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
":",
"string",
"{",
"try",
"{",
"$",
"parameters",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getTemplateVariables",
"(",
"$",
"parameters",
")",
")",
";",
"$",
"environment",
"=",
"new",
"Environment",
"(",
"new",
"ArrayLoader",
"(",
")",
")",
";",
"$",
"template",
"=",
"$",
"environment",
"->",
"createTemplate",
"(",
"$",
"string",
")",
";",
"return",
"$",
"environment",
"->",
"resolveTemplate",
"(",
"$",
"template",
")",
"->",
"render",
"(",
"$",
"parameters",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"return",
"''",
";",
"}",
"}"
]
| Renders the provided template, with a reduced set of variables from the provided
parameters list. Variables included are only those which can be safely printed. | [
"Renders",
"the",
"provided",
"template",
"with",
"a",
"reduced",
"set",
"of",
"variables",
"from",
"the",
"provided",
"parameters",
"list",
".",
"Variables",
"included",
"are",
"only",
"those",
"which",
"can",
"be",
"safely",
"printed",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php#L206-L218 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php | RenderingRuntime.getViewContext | private function getViewContext(array $context, ?string $viewContext = null): string
{
return $viewContext ?? $context['view_context'] ?? ViewInterface::CONTEXT_DEFAULT;
} | php | private function getViewContext(array $context, ?string $viewContext = null): string
{
return $viewContext ?? $context['view_context'] ?? ViewInterface::CONTEXT_DEFAULT;
} | [
"private",
"function",
"getViewContext",
"(",
"array",
"$",
"context",
",",
"?",
"string",
"$",
"viewContext",
"=",
"null",
")",
":",
"string",
"{",
"return",
"$",
"viewContext",
"??",
"$",
"context",
"[",
"'view_context'",
"]",
"??",
"ViewInterface",
"::",
"CONTEXT_DEFAULT",
";",
"}"
]
| Returns the correct view context based on provided Twig context and view context
provided through function call. | [
"Returns",
"the",
"correct",
"view",
"context",
"based",
"on",
"provided",
"Twig",
"context",
"and",
"view",
"context",
"provided",
"through",
"function",
"call",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/RenderingRuntime.php#L224-L227 | train |
netgen-layouts/layouts-core | lib/Collection/Result/ResultSet.php | ResultSet.isContextual | public function isContextual(): bool
{
$collectionQuery = $this->collection->getQuery();
if (!$collectionQuery instanceof Query) {
return false;
}
return $collectionQuery->isContextual();
} | php | public function isContextual(): bool
{
$collectionQuery = $this->collection->getQuery();
if (!$collectionQuery instanceof Query) {
return false;
}
return $collectionQuery->isContextual();
} | [
"public",
"function",
"isContextual",
"(",
")",
":",
"bool",
"{",
"$",
"collectionQuery",
"=",
"$",
"this",
"->",
"collection",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collectionQuery",
"instanceof",
"Query",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"collectionQuery",
"->",
"isContextual",
"(",
")",
";",
"}"
]
| Returns if the result set is dependent on a context, i.e. current request. | [
"Returns",
"if",
"the",
"result",
"set",
"is",
"dependent",
"on",
"a",
"context",
"i",
".",
"e",
".",
"current",
"request",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/ResultSet.php#L99-L107 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/HelpersRuntime.php | HelpersRuntime.getLocaleName | public function getLocaleName(string $locale, ?string $displayLocale = null): ?string
{
return Locales::getName($locale, $displayLocale);
} | php | public function getLocaleName(string $locale, ?string $displayLocale = null): ?string
{
return Locales::getName($locale, $displayLocale);
} | [
"public",
"function",
"getLocaleName",
"(",
"string",
"$",
"locale",
",",
"?",
"string",
"$",
"displayLocale",
"=",
"null",
")",
":",
"?",
"string",
"{",
"return",
"Locales",
"::",
"getName",
"(",
"$",
"locale",
",",
"$",
"displayLocale",
")",
";",
"}"
]
| Returns the locale name in specified locale.
If $displayLocale is specified, name translated in that locale will be returned. | [
"Returns",
"the",
"locale",
"name",
"in",
"specified",
"locale",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/HelpersRuntime.php#L29-L32 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/HelpersRuntime.php | HelpersRuntime.getLayoutName | public function getLayoutName($layoutId): string
{
try {
$layout = $this->layoutService->loadLayout($layoutId);
return $layout->getName();
} catch (Throwable $t) {
return '';
}
} | php | public function getLayoutName($layoutId): string
{
try {
$layout = $this->layoutService->loadLayout($layoutId);
return $layout->getName();
} catch (Throwable $t) {
return '';
}
} | [
"public",
"function",
"getLayoutName",
"(",
"$",
"layoutId",
")",
":",
"string",
"{",
"try",
"{",
"$",
"layout",
"=",
"$",
"this",
"->",
"layoutService",
"->",
"loadLayout",
"(",
"$",
"layoutId",
")",
";",
"return",
"$",
"layout",
"->",
"getName",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"return",
"''",
";",
"}",
"}"
]
| Returns the layout name for specified layout ID.
@param int|string $layoutId | [
"Returns",
"the",
"layout",
"name",
"for",
"specified",
"layout",
"ID",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/HelpersRuntime.php#L39-L48 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/Runtime/HelpersRuntime.php | HelpersRuntime.getCountryFlag | public function getCountryFlag(string $countryCode): string
{
try {
return FlagGenerator::fromCountryCode($countryCode);
} catch (Throwable $t) {
return $countryCode;
}
} | php | public function getCountryFlag(string $countryCode): string
{
try {
return FlagGenerator::fromCountryCode($countryCode);
} catch (Throwable $t) {
return $countryCode;
}
} | [
"public",
"function",
"getCountryFlag",
"(",
"string",
"$",
"countryCode",
")",
":",
"string",
"{",
"try",
"{",
"return",
"FlagGenerator",
"::",
"fromCountryCode",
"(",
"$",
"countryCode",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"return",
"$",
"countryCode",
";",
"}",
"}"
]
| Returns the country flag as an emoji string for provided country code.
If the flag cannot be generated, the country code is returned as is.
@param string $countryCode | [
"Returns",
"the",
"country",
"flag",
"as",
"an",
"emoji",
"string",
"for",
"provided",
"country",
"code",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/Runtime/HelpersRuntime.php#L57-L64 | train |
netgen-layouts/layouts-core | lib/Core/Validator/Validator.php | Validator.validateId | public function validateId($id, ?string $propertyPath = null): void
{
$this->validate(
$id,
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'scalar']),
],
$propertyPath
);
} | php | public function validateId($id, ?string $propertyPath = null): void
{
$this->validate(
$id,
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'scalar']),
],
$propertyPath
);
} | [
"public",
"function",
"validateId",
"(",
"$",
"id",
",",
"?",
"string",
"$",
"propertyPath",
"=",
"null",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"id",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'scalar'",
"]",
")",
",",
"]",
",",
"$",
"propertyPath",
")",
";",
"}"
]
| Validates the provided ID to be an integer or string.
Use the $propertyPath to change the name of the validated property in the error message.
@param int|string $id
@param string $propertyPath
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"ID",
"to",
"be",
"an",
"integer",
"or",
"string",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/Validator.php#L25-L35 | train |
netgen-layouts/layouts-core | lib/Core/Validator/Validator.php | Validator.validateIdentifier | public function validateIdentifier(string $identifier, ?string $propertyPath = null): void
{
$constraints = [
new Constraints\NotBlank(),
new Constraints\Regex(
[
'pattern' => '/^[A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*$/',
]
),
];
$this->validate($identifier, $constraints, $propertyPath);
} | php | public function validateIdentifier(string $identifier, ?string $propertyPath = null): void
{
$constraints = [
new Constraints\NotBlank(),
new Constraints\Regex(
[
'pattern' => '/^[A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*$/',
]
),
];
$this->validate($identifier, $constraints, $propertyPath);
} | [
"public",
"function",
"validateIdentifier",
"(",
"string",
"$",
"identifier",
",",
"?",
"string",
"$",
"propertyPath",
"=",
"null",
")",
":",
"void",
"{",
"$",
"constraints",
"=",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Regex",
"(",
"[",
"'pattern'",
"=>",
"'/^[A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*$/'",
",",
"]",
")",
",",
"]",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"identifier",
",",
"$",
"constraints",
",",
"$",
"propertyPath",
")",
";",
"}"
]
| Validates the provided identifier to be a string.
If $isRequired is set to false, null value is also allowed.
Use the $propertyPath to change the name of the validated property in the error message.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"identifier",
"to",
"be",
"a",
"string",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/Validator.php#L46-L58 | train |
netgen-layouts/layouts-core | lib/Core/Validator/Validator.php | Validator.validatePosition | public function validatePosition(?int $position, ?string $propertyPath = null, bool $isRequired = false): void
{
if (!$isRequired && $position === null) {
return;
}
$constraints = [
new Constraints\NotBlank(),
new Constraints\GreaterThanOrEqual(0),
];
$this->validate($position, $constraints, $propertyPath);
} | php | public function validatePosition(?int $position, ?string $propertyPath = null, bool $isRequired = false): void
{
if (!$isRequired && $position === null) {
return;
}
$constraints = [
new Constraints\NotBlank(),
new Constraints\GreaterThanOrEqual(0),
];
$this->validate($position, $constraints, $propertyPath);
} | [
"public",
"function",
"validatePosition",
"(",
"?",
"int",
"$",
"position",
",",
"?",
"string",
"$",
"propertyPath",
"=",
"null",
",",
"bool",
"$",
"isRequired",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"isRequired",
"&&",
"$",
"position",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"constraints",
"=",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"GreaterThanOrEqual",
"(",
"0",
")",
",",
"]",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"position",
",",
"$",
"constraints",
",",
"$",
"propertyPath",
")",
";",
"}"
]
| Validates the provided position to be an integer greater than or equal to 0.
If $isRequired is set to false, null value is also allowed.
Use the $propertyPath to change the name of the validated property in the error message.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"position",
"to",
"be",
"an",
"integer",
"greater",
"than",
"or",
"equal",
"to",
"0",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/Validator.php#L69-L81 | train |
netgen-layouts/layouts-core | lib/Core/Validator/Validator.php | Validator.validateOffsetAndLimit | public function validateOffsetAndLimit(?int $offset, ?int $limit): void
{
$this->validate(
$offset,
[
new Constraints\NotBlank(),
],
'offset'
);
if ($limit !== null) {
$this->validate(
$limit,
[
new Constraints\NotBlank(),
],
'limit'
);
}
} | php | public function validateOffsetAndLimit(?int $offset, ?int $limit): void
{
$this->validate(
$offset,
[
new Constraints\NotBlank(),
],
'offset'
);
if ($limit !== null) {
$this->validate(
$limit,
[
new Constraints\NotBlank(),
],
'limit'
);
}
} | [
"public",
"function",
"validateOffsetAndLimit",
"(",
"?",
"int",
"$",
"offset",
",",
"?",
"int",
"$",
"limit",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"offset",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"]",
",",
"'offset'",
")",
";",
"if",
"(",
"$",
"limit",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"limit",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"]",
",",
"'limit'",
")",
";",
"}",
"}"
]
| Validates the provided offset and limit values to be integers.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"offset",
"and",
"limit",
"values",
"to",
"be",
"integers",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/Validator.php#L88-L107 | train |
netgen-layouts/layouts-core | lib/Core/Validator/Validator.php | Validator.validateLocale | public function validateLocale(string $locale, ?string $propertyPath = null): void
{
$this->validate(
$locale,
[
new Constraints\NotBlank(),
new LocaleConstraint(),
],
$propertyPath
);
} | php | public function validateLocale(string $locale, ?string $propertyPath = null): void
{
$this->validate(
$locale,
[
new Constraints\NotBlank(),
new LocaleConstraint(),
],
$propertyPath
);
} | [
"public",
"function",
"validateLocale",
"(",
"string",
"$",
"locale",
",",
"?",
"string",
"$",
"propertyPath",
"=",
"null",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"locale",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"LocaleConstraint",
"(",
")",
",",
"]",
",",
"$",
"propertyPath",
")",
";",
"}"
]
| Validates the provided locale.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"locale",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/Validator.php#L114-L124 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Mapper/BlockMapper.php | BlockMapper.mapBlocks | public function mapBlocks(array $data): array
{
$blocks = [];
foreach ($data as $dataItem) {
$blockId = (int) $dataItem['id'];
$locale = $dataItem['locale'];
if (!isset($blocks[$blockId])) {
$blocks[$blockId] = [
'id' => $blockId,
'layoutId' => (int) $dataItem['layout_id'],
'depth' => (int) $dataItem['depth'],
'path' => $dataItem['path'],
'parentId' => $dataItem['parent_id'] > 0 ? (int) $dataItem['parent_id'] : null,
'placeholder' => $dataItem['placeholder'],
'position' => $dataItem['parent_id'] > 0 ? (int) $dataItem['position'] : null,
'definitionIdentifier' => $dataItem['definition_identifier'],
'viewType' => $dataItem['view_type'],
'itemViewType' => $dataItem['item_view_type'],
'name' => $dataItem['name'],
'isTranslatable' => (bool) $dataItem['translatable'],
'mainLocale' => $dataItem['main_locale'],
'alwaysAvailable' => (bool) $dataItem['always_available'],
'status' => (int) $dataItem['status'],
'config' => $this->buildParameters((string) $dataItem['config']),
];
}
$blocks[$blockId]['parameters'][$locale] = $this->buildParameters((string) $dataItem['parameters']);
$blocks[$blockId]['availableLocales'][] = $locale;
}
return array_values(
array_map(
static function (array $blockData): Block {
ksort($blockData['parameters']);
sort($blockData['availableLocales']);
return Block::fromArray($blockData);
},
$blocks
)
);
} | php | public function mapBlocks(array $data): array
{
$blocks = [];
foreach ($data as $dataItem) {
$blockId = (int) $dataItem['id'];
$locale = $dataItem['locale'];
if (!isset($blocks[$blockId])) {
$blocks[$blockId] = [
'id' => $blockId,
'layoutId' => (int) $dataItem['layout_id'],
'depth' => (int) $dataItem['depth'],
'path' => $dataItem['path'],
'parentId' => $dataItem['parent_id'] > 0 ? (int) $dataItem['parent_id'] : null,
'placeholder' => $dataItem['placeholder'],
'position' => $dataItem['parent_id'] > 0 ? (int) $dataItem['position'] : null,
'definitionIdentifier' => $dataItem['definition_identifier'],
'viewType' => $dataItem['view_type'],
'itemViewType' => $dataItem['item_view_type'],
'name' => $dataItem['name'],
'isTranslatable' => (bool) $dataItem['translatable'],
'mainLocale' => $dataItem['main_locale'],
'alwaysAvailable' => (bool) $dataItem['always_available'],
'status' => (int) $dataItem['status'],
'config' => $this->buildParameters((string) $dataItem['config']),
];
}
$blocks[$blockId]['parameters'][$locale] = $this->buildParameters((string) $dataItem['parameters']);
$blocks[$blockId]['availableLocales'][] = $locale;
}
return array_values(
array_map(
static function (array $blockData): Block {
ksort($blockData['parameters']);
sort($blockData['availableLocales']);
return Block::fromArray($blockData);
},
$blocks
)
);
} | [
"public",
"function",
"mapBlocks",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"blocks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"dataItem",
")",
"{",
"$",
"blockId",
"=",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'id'",
"]",
";",
"$",
"locale",
"=",
"$",
"dataItem",
"[",
"'locale'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"blocks",
"[",
"$",
"blockId",
"]",
")",
")",
"{",
"$",
"blocks",
"[",
"$",
"blockId",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"blockId",
",",
"'layoutId'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'layout_id'",
"]",
",",
"'depth'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'depth'",
"]",
",",
"'path'",
"=>",
"$",
"dataItem",
"[",
"'path'",
"]",
",",
"'parentId'",
"=>",
"$",
"dataItem",
"[",
"'parent_id'",
"]",
">",
"0",
"?",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'parent_id'",
"]",
":",
"null",
",",
"'placeholder'",
"=>",
"$",
"dataItem",
"[",
"'placeholder'",
"]",
",",
"'position'",
"=>",
"$",
"dataItem",
"[",
"'parent_id'",
"]",
">",
"0",
"?",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'position'",
"]",
":",
"null",
",",
"'definitionIdentifier'",
"=>",
"$",
"dataItem",
"[",
"'definition_identifier'",
"]",
",",
"'viewType'",
"=>",
"$",
"dataItem",
"[",
"'view_type'",
"]",
",",
"'itemViewType'",
"=>",
"$",
"dataItem",
"[",
"'item_view_type'",
"]",
",",
"'name'",
"=>",
"$",
"dataItem",
"[",
"'name'",
"]",
",",
"'isTranslatable'",
"=>",
"(",
"bool",
")",
"$",
"dataItem",
"[",
"'translatable'",
"]",
",",
"'mainLocale'",
"=>",
"$",
"dataItem",
"[",
"'main_locale'",
"]",
",",
"'alwaysAvailable'",
"=>",
"(",
"bool",
")",
"$",
"dataItem",
"[",
"'always_available'",
"]",
",",
"'status'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'status'",
"]",
",",
"'config'",
"=>",
"$",
"this",
"->",
"buildParameters",
"(",
"(",
"string",
")",
"$",
"dataItem",
"[",
"'config'",
"]",
")",
",",
"]",
";",
"}",
"$",
"blocks",
"[",
"$",
"blockId",
"]",
"[",
"'parameters'",
"]",
"[",
"$",
"locale",
"]",
"=",
"$",
"this",
"->",
"buildParameters",
"(",
"(",
"string",
")",
"$",
"dataItem",
"[",
"'parameters'",
"]",
")",
";",
"$",
"blocks",
"[",
"$",
"blockId",
"]",
"[",
"'availableLocales'",
"]",
"[",
"]",
"=",
"$",
"locale",
";",
"}",
"return",
"array_values",
"(",
"array_map",
"(",
"static",
"function",
"(",
"array",
"$",
"blockData",
")",
":",
"Block",
"{",
"ksort",
"(",
"$",
"blockData",
"[",
"'parameters'",
"]",
")",
";",
"sort",
"(",
"$",
"blockData",
"[",
"'availableLocales'",
"]",
")",
";",
"return",
"Block",
"::",
"fromArray",
"(",
"$",
"blockData",
")",
";",
"}",
",",
"$",
"blocks",
")",
")",
";",
"}"
]
| Maps data from database to block values.
@return \Netgen\BlockManager\Persistence\Values\Block\Block[] | [
"Maps",
"data",
"from",
"database",
"to",
"block",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Mapper/BlockMapper.php#L17-L61 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Mapper/BlockMapper.php | BlockMapper.mapCollectionReferences | public function mapCollectionReferences(array $data): array
{
$collectionReferences = [];
foreach ($data as $dataItem) {
$collectionReferences[] = CollectionReference::fromArray(
[
'blockId' => (int) $dataItem['block_id'],
'blockStatus' => (int) $dataItem['block_status'],
'collectionId' => (int) $dataItem['collection_id'],
'collectionStatus' => (int) $dataItem['collection_status'],
'identifier' => $dataItem['identifier'],
]
);
}
return $collectionReferences;
} | php | public function mapCollectionReferences(array $data): array
{
$collectionReferences = [];
foreach ($data as $dataItem) {
$collectionReferences[] = CollectionReference::fromArray(
[
'blockId' => (int) $dataItem['block_id'],
'blockStatus' => (int) $dataItem['block_status'],
'collectionId' => (int) $dataItem['collection_id'],
'collectionStatus' => (int) $dataItem['collection_status'],
'identifier' => $dataItem['identifier'],
]
);
}
return $collectionReferences;
} | [
"public",
"function",
"mapCollectionReferences",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"collectionReferences",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"dataItem",
")",
"{",
"$",
"collectionReferences",
"[",
"]",
"=",
"CollectionReference",
"::",
"fromArray",
"(",
"[",
"'blockId'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'block_id'",
"]",
",",
"'blockStatus'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'block_status'",
"]",
",",
"'collectionId'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'collection_id'",
"]",
",",
"'collectionStatus'",
"=>",
"(",
"int",
")",
"$",
"dataItem",
"[",
"'collection_status'",
"]",
",",
"'identifier'",
"=>",
"$",
"dataItem",
"[",
"'identifier'",
"]",
",",
"]",
")",
";",
"}",
"return",
"$",
"collectionReferences",
";",
"}"
]
| Maps data from database to collection reference values.
@return \Netgen\BlockManager\Persistence\Values\Block\CollectionReference[] | [
"Maps",
"data",
"from",
"database",
"to",
"collection",
"reference",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Mapper/BlockMapper.php#L68-L85 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/LayoutResolverHandler.php | LayoutResolverHandler.getRulePriority | private function getRulePriority(RuleCreateStruct $ruleCreateStruct): int
{
if (is_int($ruleCreateStruct->priority)) {
return $ruleCreateStruct->priority;
}
$lowestRulePriority = $this->queryHandler->getLowestRulePriority();
if ($lowestRulePriority !== null) {
return $lowestRulePriority - 10;
}
return 0;
} | php | private function getRulePriority(RuleCreateStruct $ruleCreateStruct): int
{
if (is_int($ruleCreateStruct->priority)) {
return $ruleCreateStruct->priority;
}
$lowestRulePriority = $this->queryHandler->getLowestRulePriority();
if ($lowestRulePriority !== null) {
return $lowestRulePriority - 10;
}
return 0;
} | [
"private",
"function",
"getRulePriority",
"(",
"RuleCreateStruct",
"$",
"ruleCreateStruct",
")",
":",
"int",
"{",
"if",
"(",
"is_int",
"(",
"$",
"ruleCreateStruct",
"->",
"priority",
")",
")",
"{",
"return",
"$",
"ruleCreateStruct",
"->",
"priority",
";",
"}",
"$",
"lowestRulePriority",
"=",
"$",
"this",
"->",
"queryHandler",
"->",
"getLowestRulePriority",
"(",
")",
";",
"if",
"(",
"$",
"lowestRulePriority",
"!==",
"null",
")",
"{",
"return",
"$",
"lowestRulePriority",
"-",
"10",
";",
"}",
"return",
"0",
";",
"}"
]
| Returns the rule priority when creating a new rule.
If priority is specified in the struct, it is used automatically. Otherwise,
the returned priority is the lowest available priority subtracted by 10 (to allow
inserting rules in between).
If no rules exist, priority is 0. | [
"Returns",
"the",
"rule",
"priority",
"when",
"creating",
"a",
"new",
"rule",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/LayoutResolverHandler.php#L321-L333 | train |
netgen-layouts/layouts-core | lib/Collection/QueryType/QueryTypeFactory.php | QueryTypeFactory.buildQueryType | public function buildQueryType(
string $type,
QueryTypeHandlerInterface $handler,
array $config
): QueryTypeInterface {
$parameterBuilder = $this->parameterBuilderFactory->createParameterBuilder();
$handler->buildParameters($parameterBuilder);
$parameterDefinitions = $parameterBuilder->buildParameterDefinitions();
return QueryType::fromArray(
[
'type' => $type,
'isEnabled' => $config['enabled'],
'name' => $config['name'] ?? '',
'handler' => $handler,
'parameterDefinitions' => $parameterDefinitions,
]
);
} | php | public function buildQueryType(
string $type,
QueryTypeHandlerInterface $handler,
array $config
): QueryTypeInterface {
$parameterBuilder = $this->parameterBuilderFactory->createParameterBuilder();
$handler->buildParameters($parameterBuilder);
$parameterDefinitions = $parameterBuilder->buildParameterDefinitions();
return QueryType::fromArray(
[
'type' => $type,
'isEnabled' => $config['enabled'],
'name' => $config['name'] ?? '',
'handler' => $handler,
'parameterDefinitions' => $parameterDefinitions,
]
);
} | [
"public",
"function",
"buildQueryType",
"(",
"string",
"$",
"type",
",",
"QueryTypeHandlerInterface",
"$",
"handler",
",",
"array",
"$",
"config",
")",
":",
"QueryTypeInterface",
"{",
"$",
"parameterBuilder",
"=",
"$",
"this",
"->",
"parameterBuilderFactory",
"->",
"createParameterBuilder",
"(",
")",
";",
"$",
"handler",
"->",
"buildParameters",
"(",
"$",
"parameterBuilder",
")",
";",
"$",
"parameterDefinitions",
"=",
"$",
"parameterBuilder",
"->",
"buildParameterDefinitions",
"(",
")",
";",
"return",
"QueryType",
"::",
"fromArray",
"(",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'isEnabled'",
"=>",
"$",
"config",
"[",
"'enabled'",
"]",
",",
"'name'",
"=>",
"$",
"config",
"[",
"'name'",
"]",
"??",
"''",
",",
"'handler'",
"=>",
"$",
"handler",
",",
"'parameterDefinitions'",
"=>",
"$",
"parameterDefinitions",
",",
"]",
")",
";",
"}"
]
| Builds the query type. | [
"Builds",
"the",
"query",
"type",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/QueryType/QueryTypeFactory.php#L24-L42 | train |
netgen-layouts/layouts-core | lib/View/ViewBuilder.php | ViewBuilder.getViewProvider | private function getViewProvider($value): ViewProviderInterface
{
foreach ($this->viewProviders as $viewProvider) {
if ($viewProvider->supports($value)) {
return $viewProvider;
}
}
throw ViewProviderException::noViewProvider(get_class($value));
} | php | private function getViewProvider($value): ViewProviderInterface
{
foreach ($this->viewProviders as $viewProvider) {
if ($viewProvider->supports($value)) {
return $viewProvider;
}
}
throw ViewProviderException::noViewProvider(get_class($value));
} | [
"private",
"function",
"getViewProvider",
"(",
"$",
"value",
")",
":",
"ViewProviderInterface",
"{",
"foreach",
"(",
"$",
"this",
"->",
"viewProviders",
"as",
"$",
"viewProvider",
")",
"{",
"if",
"(",
"$",
"viewProvider",
"->",
"supports",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"viewProvider",
";",
"}",
"}",
"throw",
"ViewProviderException",
"::",
"noViewProvider",
"(",
"get_class",
"(",
"$",
"value",
")",
")",
";",
"}"
]
| Returns the view provider that supports the given value.
@param mixed $value
@return \Netgen\BlockManager\View\Provider\ViewProviderInterface | [
"Returns",
"the",
"view",
"provider",
"that",
"supports",
"the",
"given",
"value",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/View/ViewBuilder.php#L78-L87 | train |
netgen-layouts/layouts-core | lib/View/Twig/ContextualizedTwigTemplate.php | ContextualizedTwigTemplate.renderBlock | public function renderBlock(string $blockName): string
{
if (!$this->template->hasBlock($blockName, $this->context, $this->blocks)) {
return '';
}
$level = ob_get_level();
ob_start();
try {
$this->template->displayBlock($blockName, $this->context, $this->blocks);
} catch (Throwable $t) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $t;
}
return (string) ob_get_clean();
} | php | public function renderBlock(string $blockName): string
{
if (!$this->template->hasBlock($blockName, $this->context, $this->blocks)) {
return '';
}
$level = ob_get_level();
ob_start();
try {
$this->template->displayBlock($blockName, $this->context, $this->blocks);
} catch (Throwable $t) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $t;
}
return (string) ob_get_clean();
} | [
"public",
"function",
"renderBlock",
"(",
"string",
"$",
"blockName",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"template",
"->",
"hasBlock",
"(",
"$",
"blockName",
",",
"$",
"this",
"->",
"context",
",",
"$",
"this",
"->",
"blocks",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"level",
"=",
"ob_get_level",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"template",
"->",
"displayBlock",
"(",
"$",
"blockName",
",",
"$",
"this",
"->",
"context",
",",
"$",
"this",
"->",
"blocks",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"$",
"level",
")",
"{",
"ob_end_clean",
"(",
")",
";",
"}",
"throw",
"$",
"t",
";",
"}",
"return",
"(",
"string",
")",
"ob_get_clean",
"(",
")",
";",
"}"
]
| Renders the provided block. If block does not exist, an empty string will be returned.
@throws \Throwable | [
"Renders",
"the",
"provided",
"block",
".",
"If",
"block",
"does",
"not",
"exist",
"an",
"empty",
"string",
"will",
"be",
"returned",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/View/Twig/ContextualizedTwigTemplate.php#L51-L71 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Design/Twig/FilesystemLoader.php | FilesystemLoader.getRealName | private function getRealName(string $name): string
{
if (mb_strpos($name, '@ngbm/') !== 0) {
return $name;
}
if (!isset($this->templateMap[$name])) {
$this->templateMap[$name] = str_replace(
'@ngbm/',
'@ngbm_' . $this->configuration->getParameter('design') . '/',
$name
);
}
return $this->templateMap[$name];
} | php | private function getRealName(string $name): string
{
if (mb_strpos($name, '@ngbm/') !== 0) {
return $name;
}
if (!isset($this->templateMap[$name])) {
$this->templateMap[$name] = str_replace(
'@ngbm/',
'@ngbm_' . $this->configuration->getParameter('design') . '/',
$name
);
}
return $this->templateMap[$name];
} | [
"private",
"function",
"getRealName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"if",
"(",
"mb_strpos",
"(",
"$",
"name",
",",
"'@ngbm/'",
")",
"!==",
"0",
")",
"{",
"return",
"$",
"name",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"templateMap",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"templateMap",
"[",
"$",
"name",
"]",
"=",
"str_replace",
"(",
"'@ngbm/'",
",",
"'@ngbm_'",
".",
"$",
"this",
"->",
"configuration",
"->",
"getParameter",
"(",
"'design'",
")",
".",
"'/'",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"templateMap",
"[",
"$",
"name",
"]",
";",
"}"
]
| Returns the name of the template converted from the virtual Twig namespace ("@ngbm")
to the real currently defined design name. | [
"Returns",
"the",
"name",
"of",
"the",
"template",
"converted",
"from",
"the",
"virtual",
"Twig",
"namespace",
"("
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Design/Twig/FilesystemLoader.php#L70-L85 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Design/ThemePass.php | ThemePass.getThemeDirs | private function getThemeDirs(ContainerBuilder $container, array $themeList): array
{
$paths = array_map(
static function (array $bundleMetadata): string {
return $bundleMetadata['path'] . '/Resources/views/ngbm/themes';
},
// Reversing the list of bundles so bundles added at end have higher priority
// when searching for a template
array_reverse($container->getParameter('kernel.bundles_metadata'))
);
$paths = array_values(array_filter($paths, 'is_dir'));
if ($container->hasParameter('twig.default_path')) {
$defaultTwigDir = $container->getParameterBag()->resolveValue($container->getParameter('twig.default_path')) . '/ngbm/themes';
if (is_dir($defaultTwigDir)) {
array_unshift($paths, $defaultTwigDir);
}
}
$appDir = $this->getAppDir($container) . '/Resources/views/ngbm/themes';
if (is_dir($appDir)) {
array_unshift($paths, $appDir);
}
$themeDirs = [];
foreach ($paths as $path) {
foreach ($themeList as $themeName) {
$themeDirs[$themeName][] = $path . '/' . $themeName;
}
}
return $themeDirs;
} | php | private function getThemeDirs(ContainerBuilder $container, array $themeList): array
{
$paths = array_map(
static function (array $bundleMetadata): string {
return $bundleMetadata['path'] . '/Resources/views/ngbm/themes';
},
// Reversing the list of bundles so bundles added at end have higher priority
// when searching for a template
array_reverse($container->getParameter('kernel.bundles_metadata'))
);
$paths = array_values(array_filter($paths, 'is_dir'));
if ($container->hasParameter('twig.default_path')) {
$defaultTwigDir = $container->getParameterBag()->resolveValue($container->getParameter('twig.default_path')) . '/ngbm/themes';
if (is_dir($defaultTwigDir)) {
array_unshift($paths, $defaultTwigDir);
}
}
$appDir = $this->getAppDir($container) . '/Resources/views/ngbm/themes';
if (is_dir($appDir)) {
array_unshift($paths, $appDir);
}
$themeDirs = [];
foreach ($paths as $path) {
foreach ($themeList as $themeName) {
$themeDirs[$themeName][] = $path . '/' . $themeName;
}
}
return $themeDirs;
} | [
"private",
"function",
"getThemeDirs",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"themeList",
")",
":",
"array",
"{",
"$",
"paths",
"=",
"array_map",
"(",
"static",
"function",
"(",
"array",
"$",
"bundleMetadata",
")",
":",
"string",
"{",
"return",
"$",
"bundleMetadata",
"[",
"'path'",
"]",
".",
"'/Resources/views/ngbm/themes'",
";",
"}",
",",
"// Reversing the list of bundles so bundles added at end have higher priority",
"// when searching for a template",
"array_reverse",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.bundles_metadata'",
")",
")",
")",
";",
"$",
"paths",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"paths",
",",
"'is_dir'",
")",
")",
";",
"if",
"(",
"$",
"container",
"->",
"hasParameter",
"(",
"'twig.default_path'",
")",
")",
"{",
"$",
"defaultTwigDir",
"=",
"$",
"container",
"->",
"getParameterBag",
"(",
")",
"->",
"resolveValue",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'twig.default_path'",
")",
")",
".",
"'/ngbm/themes'",
";",
"if",
"(",
"is_dir",
"(",
"$",
"defaultTwigDir",
")",
")",
"{",
"array_unshift",
"(",
"$",
"paths",
",",
"$",
"defaultTwigDir",
")",
";",
"}",
"}",
"$",
"appDir",
"=",
"$",
"this",
"->",
"getAppDir",
"(",
"$",
"container",
")",
".",
"'/Resources/views/ngbm/themes'",
";",
"if",
"(",
"is_dir",
"(",
"$",
"appDir",
")",
")",
"{",
"array_unshift",
"(",
"$",
"paths",
",",
"$",
"appDir",
")",
";",
"}",
"$",
"themeDirs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"themeList",
"as",
"$",
"themeName",
")",
"{",
"$",
"themeDirs",
"[",
"$",
"themeName",
"]",
"[",
"]",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"themeName",
";",
"}",
"}",
"return",
"$",
"themeDirs",
";",
"}"
]
| Returns an array with all found paths for provided theme list. | [
"Returns",
"an",
"array",
"with",
"all",
"found",
"paths",
"for",
"provided",
"theme",
"list",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Design/ThemePass.php#L45-L78 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Design/ThemePass.php | ThemePass.getAppDir | private function getAppDir(ContainerBuilder $container): string
{
if ($container->hasParameter('kernel.project_dir')) {
return (string) $container->getParameter('kernel.project_dir') . '/' . (string) $container->getParameter('kernel.name');
}
return (string) $container->getParameter('kernel.root_dir');
} | php | private function getAppDir(ContainerBuilder $container): string
{
if ($container->hasParameter('kernel.project_dir')) {
return (string) $container->getParameter('kernel.project_dir') . '/' . (string) $container->getParameter('kernel.name');
}
return (string) $container->getParameter('kernel.root_dir');
} | [
"private",
"function",
"getAppDir",
"(",
"ContainerBuilder",
"$",
"container",
")",
":",
"string",
"{",
"if",
"(",
"$",
"container",
"->",
"hasParameter",
"(",
"'kernel.project_dir'",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.project_dir'",
")",
".",
"'/'",
".",
"(",
"string",
")",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.name'",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.root_dir'",
")",
";",
"}"
]
| Returns the current app dir, abstracting Symfony 3.3+, where kernel.project_dir is available,
and Symfony 2.8 support, where only kernel.root_dir exists. | [
"Returns",
"the",
"current",
"app",
"dir",
"abstracting",
"Symfony",
"3",
".",
"3",
"+",
"where",
"kernel",
".",
"project_dir",
"is",
"available",
"and",
"Symfony",
"2",
".",
"8",
"support",
"where",
"only",
"kernel",
".",
"root_dir",
"exists",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Design/ThemePass.php#L84-L91 | train |
netgen-layouts/layouts-core | lib/Serializer/Normalizer/V1/BlockNormalizer.php | BlockNormalizer.buildVersionedValues | private function buildVersionedValues(iterable $values, int $version): Generator
{
foreach ($values as $key => $value) {
yield $key => new VersionedValue($value, $version);
}
} | php | private function buildVersionedValues(iterable $values, int $version): Generator
{
foreach ($values as $key => $value) {
yield $key => new VersionedValue($value, $version);
}
} | [
"private",
"function",
"buildVersionedValues",
"(",
"iterable",
"$",
"values",
",",
"int",
"$",
"version",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"yield",
"$",
"key",
"=>",
"new",
"VersionedValue",
"(",
"$",
"value",
",",
"$",
"version",
")",
";",
"}",
"}"
]
| Builds the list of VersionedValue objects for provided list of values. | [
"Builds",
"the",
"list",
"of",
"VersionedValue",
"objects",
"for",
"provided",
"list",
"of",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Serializer/Normalizer/V1/BlockNormalizer.php#L96-L101 | train |
netgen-layouts/layouts-core | lib/Core/Service/CollectionService.php | CollectionService.updateQueryTranslations | private function updateQueryTranslations(QueryTypeInterface $queryType, PersistenceQuery $persistenceQuery, APIQueryUpdateStruct $queryUpdateStruct): PersistenceQuery
{
if ($queryUpdateStruct->locale === $persistenceQuery->mainLocale) {
$persistenceQuery = $this->collectionHandler->updateQueryTranslation(
$persistenceQuery,
$queryUpdateStruct->locale,
QueryTranslationUpdateStruct::fromArray(
[
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$queryType,
$queryUpdateStruct->getParameterValues(),
$persistenceQuery->parameters[$persistenceQuery->mainLocale]
)
),
]
)
);
}
$untranslatableParams = iterator_to_array(
$this->parameterMapper->extractUntranslatableParameters(
$queryType,
$persistenceQuery->parameters[$persistenceQuery->mainLocale]
)
);
$localesToUpdate = [$queryUpdateStruct->locale];
if ($persistenceQuery->mainLocale === $queryUpdateStruct->locale) {
$localesToUpdate = $persistenceQuery->availableLocales;
// Remove the main locale from the array, since we already updated that one
$mainLocaleOffset = array_search($persistenceQuery->mainLocale, $persistenceQuery->availableLocales, true);
if (is_int($mainLocaleOffset)) {
array_splice($localesToUpdate, $mainLocaleOffset, 1);
}
}
foreach ($localesToUpdate as $locale) {
$params = $persistenceQuery->parameters[$locale];
if ($locale === $queryUpdateStruct->locale) {
$params = iterator_to_array(
$this->parameterMapper->serializeValues(
$queryType,
$queryUpdateStruct->getParameterValues(),
$params
)
);
}
$persistenceQuery = $this->collectionHandler->updateQueryTranslation(
$persistenceQuery,
$locale,
QueryTranslationUpdateStruct::fromArray(
[
'parameters' => $untranslatableParams + $params,
]
)
);
}
return $persistenceQuery;
} | php | private function updateQueryTranslations(QueryTypeInterface $queryType, PersistenceQuery $persistenceQuery, APIQueryUpdateStruct $queryUpdateStruct): PersistenceQuery
{
if ($queryUpdateStruct->locale === $persistenceQuery->mainLocale) {
$persistenceQuery = $this->collectionHandler->updateQueryTranslation(
$persistenceQuery,
$queryUpdateStruct->locale,
QueryTranslationUpdateStruct::fromArray(
[
'parameters' => iterator_to_array(
$this->parameterMapper->serializeValues(
$queryType,
$queryUpdateStruct->getParameterValues(),
$persistenceQuery->parameters[$persistenceQuery->mainLocale]
)
),
]
)
);
}
$untranslatableParams = iterator_to_array(
$this->parameterMapper->extractUntranslatableParameters(
$queryType,
$persistenceQuery->parameters[$persistenceQuery->mainLocale]
)
);
$localesToUpdate = [$queryUpdateStruct->locale];
if ($persistenceQuery->mainLocale === $queryUpdateStruct->locale) {
$localesToUpdate = $persistenceQuery->availableLocales;
// Remove the main locale from the array, since we already updated that one
$mainLocaleOffset = array_search($persistenceQuery->mainLocale, $persistenceQuery->availableLocales, true);
if (is_int($mainLocaleOffset)) {
array_splice($localesToUpdate, $mainLocaleOffset, 1);
}
}
foreach ($localesToUpdate as $locale) {
$params = $persistenceQuery->parameters[$locale];
if ($locale === $queryUpdateStruct->locale) {
$params = iterator_to_array(
$this->parameterMapper->serializeValues(
$queryType,
$queryUpdateStruct->getParameterValues(),
$params
)
);
}
$persistenceQuery = $this->collectionHandler->updateQueryTranslation(
$persistenceQuery,
$locale,
QueryTranslationUpdateStruct::fromArray(
[
'parameters' => $untranslatableParams + $params,
]
)
);
}
return $persistenceQuery;
} | [
"private",
"function",
"updateQueryTranslations",
"(",
"QueryTypeInterface",
"$",
"queryType",
",",
"PersistenceQuery",
"$",
"persistenceQuery",
",",
"APIQueryUpdateStruct",
"$",
"queryUpdateStruct",
")",
":",
"PersistenceQuery",
"{",
"if",
"(",
"$",
"queryUpdateStruct",
"->",
"locale",
"===",
"$",
"persistenceQuery",
"->",
"mainLocale",
")",
"{",
"$",
"persistenceQuery",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"updateQueryTranslation",
"(",
"$",
"persistenceQuery",
",",
"$",
"queryUpdateStruct",
"->",
"locale",
",",
"QueryTranslationUpdateStruct",
"::",
"fromArray",
"(",
"[",
"'parameters'",
"=>",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"serializeValues",
"(",
"$",
"queryType",
",",
"$",
"queryUpdateStruct",
"->",
"getParameterValues",
"(",
")",
",",
"$",
"persistenceQuery",
"->",
"parameters",
"[",
"$",
"persistenceQuery",
"->",
"mainLocale",
"]",
")",
")",
",",
"]",
")",
")",
";",
"}",
"$",
"untranslatableParams",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"extractUntranslatableParameters",
"(",
"$",
"queryType",
",",
"$",
"persistenceQuery",
"->",
"parameters",
"[",
"$",
"persistenceQuery",
"->",
"mainLocale",
"]",
")",
")",
";",
"$",
"localesToUpdate",
"=",
"[",
"$",
"queryUpdateStruct",
"->",
"locale",
"]",
";",
"if",
"(",
"$",
"persistenceQuery",
"->",
"mainLocale",
"===",
"$",
"queryUpdateStruct",
"->",
"locale",
")",
"{",
"$",
"localesToUpdate",
"=",
"$",
"persistenceQuery",
"->",
"availableLocales",
";",
"// Remove the main locale from the array, since we already updated that one",
"$",
"mainLocaleOffset",
"=",
"array_search",
"(",
"$",
"persistenceQuery",
"->",
"mainLocale",
",",
"$",
"persistenceQuery",
"->",
"availableLocales",
",",
"true",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"mainLocaleOffset",
")",
")",
"{",
"array_splice",
"(",
"$",
"localesToUpdate",
",",
"$",
"mainLocaleOffset",
",",
"1",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"localesToUpdate",
"as",
"$",
"locale",
")",
"{",
"$",
"params",
"=",
"$",
"persistenceQuery",
"->",
"parameters",
"[",
"$",
"locale",
"]",
";",
"if",
"(",
"$",
"locale",
"===",
"$",
"queryUpdateStruct",
"->",
"locale",
")",
"{",
"$",
"params",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"parameterMapper",
"->",
"serializeValues",
"(",
"$",
"queryType",
",",
"$",
"queryUpdateStruct",
"->",
"getParameterValues",
"(",
")",
",",
"$",
"params",
")",
")",
";",
"}",
"$",
"persistenceQuery",
"=",
"$",
"this",
"->",
"collectionHandler",
"->",
"updateQueryTranslation",
"(",
"$",
"persistenceQuery",
",",
"$",
"locale",
",",
"QueryTranslationUpdateStruct",
"::",
"fromArray",
"(",
"[",
"'parameters'",
"=>",
"$",
"untranslatableParams",
"+",
"$",
"params",
",",
"]",
")",
")",
";",
"}",
"return",
"$",
"persistenceQuery",
";",
"}"
]
| Updates translations for specified query.
This makes sure that untranslatable parameters are always kept in sync between all
available translations in the query. This means that if main translation is updated,
all other translations need to be updated too to reflect changes to untranslatable params,
and if any other translation is updated, it needs to take values of untranslatable params
from the main translation. | [
"Updates",
"translations",
"for",
"specified",
"query",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Service/CollectionService.php#L450-L513 | train |
netgen-layouts/layouts-core | lib/API/Values/Config/ConfigAwareStructTrait.php | ConfigAwareStructTrait.setConfigStruct | public function setConfigStruct(string $configKey, ConfigStruct $configStruct): void
{
$this->configStructs[$configKey] = $configStruct;
} | php | public function setConfigStruct(string $configKey, ConfigStruct $configStruct): void
{
$this->configStructs[$configKey] = $configStruct;
} | [
"public",
"function",
"setConfigStruct",
"(",
"string",
"$",
"configKey",
",",
"ConfigStruct",
"$",
"configStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"configStructs",
"[",
"$",
"configKey",
"]",
"=",
"$",
"configStruct",
";",
"}"
]
| Sets the config struct to this struct. | [
"Sets",
"the",
"config",
"struct",
"to",
"this",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/API/Values/Config/ConfigAwareStructTrait.php#L19-L22 | train |
netgen-layouts/layouts-core | lib/API/Values/Config/ConfigAwareStructTrait.php | ConfigAwareStructTrait.getConfigStruct | public function getConfigStruct(string $configKey): ConfigStruct
{
if (!$this->hasConfigStruct($configKey)) {
throw ConfigException::noConfigStruct($configKey);
}
return $this->configStructs[$configKey];
} | php | public function getConfigStruct(string $configKey): ConfigStruct
{
if (!$this->hasConfigStruct($configKey)) {
throw ConfigException::noConfigStruct($configKey);
}
return $this->configStructs[$configKey];
} | [
"public",
"function",
"getConfigStruct",
"(",
"string",
"$",
"configKey",
")",
":",
"ConfigStruct",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasConfigStruct",
"(",
"$",
"configKey",
")",
")",
"{",
"throw",
"ConfigException",
"::",
"noConfigStruct",
"(",
"$",
"configKey",
")",
";",
"}",
"return",
"$",
"this",
"->",
"configStructs",
"[",
"$",
"configKey",
"]",
";",
"}"
]
| Gets the config struct with provided config key.
@throws \Netgen\BlockManager\Exception\API\ConfigException If config struct does not exist | [
"Gets",
"the",
"config",
"struct",
"with",
"provided",
"config",
"key",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/API/Values/Config/ConfigAwareStructTrait.php#L37-L44 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/CollectionHandler.php | CollectionHandler.createItemPosition | private function createItemPosition(Collection $collection, ?int $newPosition): int
{
if (!$this->isCollectionDynamic($collection)) {
return $this->positionHelper->createPosition(
$this->getPositionHelperItemConditions(
$collection->id,
$collection->status
),
$newPosition
);
}
if ($newPosition === null) {
throw new BadStateException('collection', 'When adding items to dynamic collections, position is mandatory.');
}
return $this->incrementItemPositions($collection, $newPosition);
} | php | private function createItemPosition(Collection $collection, ?int $newPosition): int
{
if (!$this->isCollectionDynamic($collection)) {
return $this->positionHelper->createPosition(
$this->getPositionHelperItemConditions(
$collection->id,
$collection->status
),
$newPosition
);
}
if ($newPosition === null) {
throw new BadStateException('collection', 'When adding items to dynamic collections, position is mandatory.');
}
return $this->incrementItemPositions($collection, $newPosition);
} | [
"private",
"function",
"createItemPosition",
"(",
"Collection",
"$",
"collection",
",",
"?",
"int",
"$",
"newPosition",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCollectionDynamic",
"(",
"$",
"collection",
")",
")",
"{",
"return",
"$",
"this",
"->",
"positionHelper",
"->",
"createPosition",
"(",
"$",
"this",
"->",
"getPositionHelperItemConditions",
"(",
"$",
"collection",
"->",
"id",
",",
"$",
"collection",
"->",
"status",
")",
",",
"$",
"newPosition",
")",
";",
"}",
"if",
"(",
"$",
"newPosition",
"===",
"null",
")",
"{",
"throw",
"new",
"BadStateException",
"(",
"'collection'",
",",
"'When adding items to dynamic collections, position is mandatory.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"incrementItemPositions",
"(",
"$",
"collection",
",",
"$",
"newPosition",
")",
";",
"}"
]
| Creates space for a new manual item by shifting positions of other items
below the new position.
In case of a manual collection, the case is simple, all items below the position
are incremented.
In case of a dynamic collection, the items below are incremented, but only up
until the first break in positions. | [
"Creates",
"space",
"for",
"a",
"new",
"manual",
"item",
"by",
"shifting",
"positions",
"of",
"other",
"items",
"below",
"the",
"new",
"position",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/CollectionHandler.php#L546-L563 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/CollectionHandler.php | CollectionHandler.moveItemToPosition | private function moveItemToPosition(Collection $collection, Item $item, int $newPosition): int
{
if (!$this->isCollectionDynamic($collection)) {
return $this->positionHelper->moveToPosition(
$this->getPositionHelperItemConditions(
$collection->id,
$collection->status
),
$item->position,
$newPosition
);
}
return $this->incrementItemPositions($collection, $newPosition, $item->position);
} | php | private function moveItemToPosition(Collection $collection, Item $item, int $newPosition): int
{
if (!$this->isCollectionDynamic($collection)) {
return $this->positionHelper->moveToPosition(
$this->getPositionHelperItemConditions(
$collection->id,
$collection->status
),
$item->position,
$newPosition
);
}
return $this->incrementItemPositions($collection, $newPosition, $item->position);
} | [
"private",
"function",
"moveItemToPosition",
"(",
"Collection",
"$",
"collection",
",",
"Item",
"$",
"item",
",",
"int",
"$",
"newPosition",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCollectionDynamic",
"(",
"$",
"collection",
")",
")",
"{",
"return",
"$",
"this",
"->",
"positionHelper",
"->",
"moveToPosition",
"(",
"$",
"this",
"->",
"getPositionHelperItemConditions",
"(",
"$",
"collection",
"->",
"id",
",",
"$",
"collection",
"->",
"status",
")",
",",
"$",
"item",
"->",
"position",
",",
"$",
"newPosition",
")",
";",
"}",
"return",
"$",
"this",
"->",
"incrementItemPositions",
"(",
"$",
"collection",
",",
"$",
"newPosition",
",",
"$",
"item",
"->",
"position",
")",
";",
"}"
]
| Moves the item to provided position.
In case of a manual collection, the case is simple, only positions between the old
and new position are ever updated.
In case of a dynamic collection, the items below the new position are incremented,
but only up until the first break in positions. The positions are never decremented. | [
"Moves",
"the",
"item",
"to",
"provided",
"position",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/CollectionHandler.php#L574-L588 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Command/ImportCommand.php | ImportCommand.importData | private function importData(string $data): int
{
$errorCount = 0;
foreach ($this->importer->importData($data) as $index => $result) {
if ($result instanceof SuccessResult) {
$this->io->note(
sprintf(
'Imported %1$s #%2$d into %1$s ID %3$d',
$result->getEntityType(),
$index + 1,
$result->getEntityId()
)
);
continue;
}
if ($result instanceof ErrorResult) {
$this->io->error(sprintf('Could not import %s #%d', $result->getEntityType(), $index + 1));
$this->io->section('Error stack:');
$this->renderThrowableStack($result->getError());
$this->io->newLine();
++$errorCount;
continue;
}
}
return $errorCount;
} | php | private function importData(string $data): int
{
$errorCount = 0;
foreach ($this->importer->importData($data) as $index => $result) {
if ($result instanceof SuccessResult) {
$this->io->note(
sprintf(
'Imported %1$s #%2$d into %1$s ID %3$d',
$result->getEntityType(),
$index + 1,
$result->getEntityId()
)
);
continue;
}
if ($result instanceof ErrorResult) {
$this->io->error(sprintf('Could not import %s #%d', $result->getEntityType(), $index + 1));
$this->io->section('Error stack:');
$this->renderThrowableStack($result->getError());
$this->io->newLine();
++$errorCount;
continue;
}
}
return $errorCount;
} | [
"private",
"function",
"importData",
"(",
"string",
"$",
"data",
")",
":",
"int",
"{",
"$",
"errorCount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"importer",
"->",
"importData",
"(",
"$",
"data",
")",
"as",
"$",
"index",
"=>",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"instanceof",
"SuccessResult",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"note",
"(",
"sprintf",
"(",
"'Imported %1$s #%2$d into %1$s ID %3$d'",
",",
"$",
"result",
"->",
"getEntityType",
"(",
")",
",",
"$",
"index",
"+",
"1",
",",
"$",
"result",
"->",
"getEntityId",
"(",
")",
")",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"result",
"instanceof",
"ErrorResult",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"error",
"(",
"sprintf",
"(",
"'Could not import %s #%d'",
",",
"$",
"result",
"->",
"getEntityType",
"(",
")",
",",
"$",
"index",
"+",
"1",
")",
")",
";",
"$",
"this",
"->",
"io",
"->",
"section",
"(",
"'Error stack:'",
")",
";",
"$",
"this",
"->",
"renderThrowableStack",
"(",
"$",
"result",
"->",
"getError",
"(",
")",
")",
";",
"$",
"this",
"->",
"io",
"->",
"newLine",
"(",
")",
";",
"++",
"$",
"errorCount",
";",
"continue",
";",
"}",
"}",
"return",
"$",
"errorCount",
";",
"}"
]
| Import new entities from the given data and returns the error count. | [
"Import",
"new",
"entities",
"from",
"the",
"given",
"data",
"and",
"returns",
"the",
"error",
"count",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Command/ImportCommand.php#L71-L102 | train |
netgen-layouts/layouts-core | lib/API/Values/Collection/Collection.php | Collection.hasItem | public function hasItem(int $position): bool
{
return $this->items->exists(
static function ($key, APIItem $item) use ($position): bool {
return $item->getPosition() === $position;
}
);
} | php | public function hasItem(int $position): bool
{
return $this->items->exists(
static function ($key, APIItem $item) use ($position): bool {
return $item->getPosition() === $position;
}
);
} | [
"public",
"function",
"hasItem",
"(",
"int",
"$",
"position",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"items",
"->",
"exists",
"(",
"static",
"function",
"(",
"$",
"key",
",",
"APIItem",
"$",
"item",
")",
"use",
"(",
"$",
"position",
")",
":",
"bool",
"{",
"return",
"$",
"item",
"->",
"getPosition",
"(",
")",
"===",
"$",
"position",
";",
"}",
")",
";",
"}"
]
| Returns if the item exists at specified position. | [
"Returns",
"if",
"the",
"item",
"exists",
"at",
"specified",
"position",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/API/Values/Collection/Collection.php#L120-L127 | train |
netgen-layouts/layouts-core | lib/API/Values/Collection/Collection.php | Collection.getItem | public function getItem(int $position): ?APIItem
{
foreach ($this->items as $item) {
if ($item->getPosition() === $position) {
return $item;
}
}
return null;
} | php | public function getItem(int $position): ?APIItem
{
foreach ($this->items as $item) {
if ($item->getPosition() === $position) {
return $item;
}
}
return null;
} | [
"public",
"function",
"getItem",
"(",
"int",
"$",
"position",
")",
":",
"?",
"APIItem",
"{",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getPosition",
"(",
")",
"===",
"$",
"position",
")",
"{",
"return",
"$",
"item",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Returns the item at specified position. | [
"Returns",
"the",
"item",
"at",
"specified",
"position",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/API/Values/Collection/Collection.php#L132-L141 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/EventListener/BlockView/GetCollectionPagerListener.php | GetCollectionPagerListener.getMaxPages | private function getMaxPages(Block $block): ?int
{
if (!$block->getDefinition()->hasPlugin(PagedCollectionsPlugin::class)) {
return null;
}
if ($block->getParameter('paged_collections:enabled')->getValue() !== true) {
return null;
}
return $block->getParameter('paged_collections:max_pages')->getValue();
} | php | private function getMaxPages(Block $block): ?int
{
if (!$block->getDefinition()->hasPlugin(PagedCollectionsPlugin::class)) {
return null;
}
if ($block->getParameter('paged_collections:enabled')->getValue() !== true) {
return null;
}
return $block->getParameter('paged_collections:max_pages')->getValue();
} | [
"private",
"function",
"getMaxPages",
"(",
"Block",
"$",
"block",
")",
":",
"?",
"int",
"{",
"if",
"(",
"!",
"$",
"block",
"->",
"getDefinition",
"(",
")",
"->",
"hasPlugin",
"(",
"PagedCollectionsPlugin",
"::",
"class",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"block",
"->",
"getParameter",
"(",
"'paged_collections:enabled'",
")",
"->",
"getValue",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"block",
"->",
"getParameter",
"(",
"'paged_collections:max_pages'",
")",
"->",
"getValue",
"(",
")",
";",
"}"
]
| Returns the maximum number of the pages for the provided block,
if paging is enabled and maximum number of pages is set for a block. | [
"Returns",
"the",
"maximum",
"number",
"of",
"the",
"pages",
"for",
"the",
"provided",
"block",
"if",
"paging",
"is",
"enabled",
"and",
"maximum",
"number",
"of",
"pages",
"is",
"set",
"for",
"a",
"block",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/EventListener/BlockView/GetCollectionPagerListener.php#L86-L97 | train |
netgen-layouts/layouts-core | lib/Collection/Item/ItemDefinitionFactory.php | ItemDefinitionFactory.buildItemDefinition | public function buildItemDefinition(string $valueType, array $configDefinitionHandlers): ItemDefinitionInterface
{
$configDefinitions = [];
foreach ($configDefinitionHandlers as $configKey => $configDefinitionHandler) {
$configDefinitions[$configKey] = $this->configDefinitionFactory->buildConfigDefinition(
$configKey,
$configDefinitionHandler
);
}
return ItemDefinition::fromArray(
[
'valueType' => $valueType,
'configDefinitions' => $configDefinitions,
]
);
} | php | public function buildItemDefinition(string $valueType, array $configDefinitionHandlers): ItemDefinitionInterface
{
$configDefinitions = [];
foreach ($configDefinitionHandlers as $configKey => $configDefinitionHandler) {
$configDefinitions[$configKey] = $this->configDefinitionFactory->buildConfigDefinition(
$configKey,
$configDefinitionHandler
);
}
return ItemDefinition::fromArray(
[
'valueType' => $valueType,
'configDefinitions' => $configDefinitions,
]
);
} | [
"public",
"function",
"buildItemDefinition",
"(",
"string",
"$",
"valueType",
",",
"array",
"$",
"configDefinitionHandlers",
")",
":",
"ItemDefinitionInterface",
"{",
"$",
"configDefinitions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"configDefinitionHandlers",
"as",
"$",
"configKey",
"=>",
"$",
"configDefinitionHandler",
")",
"{",
"$",
"configDefinitions",
"[",
"$",
"configKey",
"]",
"=",
"$",
"this",
"->",
"configDefinitionFactory",
"->",
"buildConfigDefinition",
"(",
"$",
"configKey",
",",
"$",
"configDefinitionHandler",
")",
";",
"}",
"return",
"ItemDefinition",
"::",
"fromArray",
"(",
"[",
"'valueType'",
"=>",
"$",
"valueType",
",",
"'configDefinitions'",
"=>",
"$",
"configDefinitions",
",",
"]",
")",
";",
"}"
]
| Builds the item definition.
@param string $valueType
@param \Netgen\BlockManager\Config\ConfigDefinitionHandlerInterface[] $configDefinitionHandlers
@return \Netgen\BlockManager\Collection\Item\ItemDefinitionInterface | [
"Builds",
"the",
"item",
"definition",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Item/ItemDefinitionFactory.php#L29-L45 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/BlockStructBuilder.php | BlockStructBuilder.newBlockCreateStruct | public function newBlockCreateStruct(BlockDefinitionInterface $blockDefinition): BlockCreateStruct
{
$viewTypeIdentifier = $blockDefinition->getViewTypeIdentifiers()[0];
$viewType = $blockDefinition->getViewType($viewTypeIdentifier);
$itemViewTypeIdentifier = $viewType->getItemViewTypeIdentifiers()[0];
$blockCreateStruct = new BlockCreateStruct($blockDefinition);
$blockCreateStruct->viewType = $viewTypeIdentifier;
$blockCreateStruct->itemViewType = $itemViewTypeIdentifier;
$blockCreateStruct->isTranslatable = $blockDefinition->isTranslatable();
$blockCreateStruct->alwaysAvailable = true;
return $blockCreateStruct;
} | php | public function newBlockCreateStruct(BlockDefinitionInterface $blockDefinition): BlockCreateStruct
{
$viewTypeIdentifier = $blockDefinition->getViewTypeIdentifiers()[0];
$viewType = $blockDefinition->getViewType($viewTypeIdentifier);
$itemViewTypeIdentifier = $viewType->getItemViewTypeIdentifiers()[0];
$blockCreateStruct = new BlockCreateStruct($blockDefinition);
$blockCreateStruct->viewType = $viewTypeIdentifier;
$blockCreateStruct->itemViewType = $itemViewTypeIdentifier;
$blockCreateStruct->isTranslatable = $blockDefinition->isTranslatable();
$blockCreateStruct->alwaysAvailable = true;
return $blockCreateStruct;
} | [
"public",
"function",
"newBlockCreateStruct",
"(",
"BlockDefinitionInterface",
"$",
"blockDefinition",
")",
":",
"BlockCreateStruct",
"{",
"$",
"viewTypeIdentifier",
"=",
"$",
"blockDefinition",
"->",
"getViewTypeIdentifiers",
"(",
")",
"[",
"0",
"]",
";",
"$",
"viewType",
"=",
"$",
"blockDefinition",
"->",
"getViewType",
"(",
"$",
"viewTypeIdentifier",
")",
";",
"$",
"itemViewTypeIdentifier",
"=",
"$",
"viewType",
"->",
"getItemViewTypeIdentifiers",
"(",
")",
"[",
"0",
"]",
";",
"$",
"blockCreateStruct",
"=",
"new",
"BlockCreateStruct",
"(",
"$",
"blockDefinition",
")",
";",
"$",
"blockCreateStruct",
"->",
"viewType",
"=",
"$",
"viewTypeIdentifier",
";",
"$",
"blockCreateStruct",
"->",
"itemViewType",
"=",
"$",
"itemViewTypeIdentifier",
";",
"$",
"blockCreateStruct",
"->",
"isTranslatable",
"=",
"$",
"blockDefinition",
"->",
"isTranslatable",
"(",
")",
";",
"$",
"blockCreateStruct",
"->",
"alwaysAvailable",
"=",
"true",
";",
"return",
"$",
"blockCreateStruct",
";",
"}"
]
| Creates a new block create struct from data found in provided block definition. | [
"Creates",
"a",
"new",
"block",
"create",
"struct",
"from",
"data",
"found",
"in",
"provided",
"block",
"definition",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/BlockStructBuilder.php#L27-L40 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/BlockStructBuilder.php | BlockStructBuilder.newBlockUpdateStruct | public function newBlockUpdateStruct(string $locale, ?Block $block = null): BlockUpdateStruct
{
$blockUpdateStruct = new BlockUpdateStruct();
$blockUpdateStruct->locale = $locale;
if (!$block instanceof Block) {
return $blockUpdateStruct;
}
$blockUpdateStruct->viewType = $block->getViewType();
$blockUpdateStruct->itemViewType = $block->getItemViewType();
$blockUpdateStruct->name = $block->getName();
$blockUpdateStruct->alwaysAvailable = $block->isAlwaysAvailable();
$blockUpdateStruct->fillParametersFromBlock($block);
$this->configStructBuilder->buildConfigUpdateStructs($block, $blockUpdateStruct);
return $blockUpdateStruct;
} | php | public function newBlockUpdateStruct(string $locale, ?Block $block = null): BlockUpdateStruct
{
$blockUpdateStruct = new BlockUpdateStruct();
$blockUpdateStruct->locale = $locale;
if (!$block instanceof Block) {
return $blockUpdateStruct;
}
$blockUpdateStruct->viewType = $block->getViewType();
$blockUpdateStruct->itemViewType = $block->getItemViewType();
$blockUpdateStruct->name = $block->getName();
$blockUpdateStruct->alwaysAvailable = $block->isAlwaysAvailable();
$blockUpdateStruct->fillParametersFromBlock($block);
$this->configStructBuilder->buildConfigUpdateStructs($block, $blockUpdateStruct);
return $blockUpdateStruct;
} | [
"public",
"function",
"newBlockUpdateStruct",
"(",
"string",
"$",
"locale",
",",
"?",
"Block",
"$",
"block",
"=",
"null",
")",
":",
"BlockUpdateStruct",
"{",
"$",
"blockUpdateStruct",
"=",
"new",
"BlockUpdateStruct",
"(",
")",
";",
"$",
"blockUpdateStruct",
"->",
"locale",
"=",
"$",
"locale",
";",
"if",
"(",
"!",
"$",
"block",
"instanceof",
"Block",
")",
"{",
"return",
"$",
"blockUpdateStruct",
";",
"}",
"$",
"blockUpdateStruct",
"->",
"viewType",
"=",
"$",
"block",
"->",
"getViewType",
"(",
")",
";",
"$",
"blockUpdateStruct",
"->",
"itemViewType",
"=",
"$",
"block",
"->",
"getItemViewType",
"(",
")",
";",
"$",
"blockUpdateStruct",
"->",
"name",
"=",
"$",
"block",
"->",
"getName",
"(",
")",
";",
"$",
"blockUpdateStruct",
"->",
"alwaysAvailable",
"=",
"$",
"block",
"->",
"isAlwaysAvailable",
"(",
")",
";",
"$",
"blockUpdateStruct",
"->",
"fillParametersFromBlock",
"(",
"$",
"block",
")",
";",
"$",
"this",
"->",
"configStructBuilder",
"->",
"buildConfigUpdateStructs",
"(",
"$",
"block",
",",
"$",
"blockUpdateStruct",
")",
";",
"return",
"$",
"blockUpdateStruct",
";",
"}"
]
| Creates a new block update struct in specified locale.
If block is provided, initial data is copied from the block. | [
"Creates",
"a",
"new",
"block",
"update",
"struct",
"in",
"specified",
"locale",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/BlockStructBuilder.php#L47-L65 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/Configuration.php | Configuration.getNodes | private function getNodes(): array
{
return [
new ConfigurationNode\ViewNode(),
new ConfigurationNode\DesignNode(),
new ConfigurationNode\DesignListNode(),
new ConfigurationNode\DefaultViewTemplatesNode(),
new ConfigurationNode\HttpCacheNode(),
new ConfigurationNode\BlockDefinitionNode(),
new ConfigurationNode\BlockTypeNode(),
new ConfigurationNode\BlockTypeGroupNode(),
new ConfigurationNode\LayoutTypeNode(),
new ConfigurationNode\QueryTypeNode(),
new ConfigurationNode\PageLayoutNode(),
new ConfigurationNode\ApiKeysNode(),
new ConfigurationNode\ValueTypeNode(),
new ConfigurationNode\DebugNode(),
];
} | php | private function getNodes(): array
{
return [
new ConfigurationNode\ViewNode(),
new ConfigurationNode\DesignNode(),
new ConfigurationNode\DesignListNode(),
new ConfigurationNode\DefaultViewTemplatesNode(),
new ConfigurationNode\HttpCacheNode(),
new ConfigurationNode\BlockDefinitionNode(),
new ConfigurationNode\BlockTypeNode(),
new ConfigurationNode\BlockTypeGroupNode(),
new ConfigurationNode\LayoutTypeNode(),
new ConfigurationNode\QueryTypeNode(),
new ConfigurationNode\PageLayoutNode(),
new ConfigurationNode\ApiKeysNode(),
new ConfigurationNode\ValueTypeNode(),
new ConfigurationNode\DebugNode(),
];
} | [
"private",
"function",
"getNodes",
"(",
")",
":",
"array",
"{",
"return",
"[",
"new",
"ConfigurationNode",
"\\",
"ViewNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"DesignNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"DesignListNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"DefaultViewTemplatesNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"HttpCacheNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"BlockDefinitionNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"BlockTypeNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"BlockTypeGroupNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"LayoutTypeNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"QueryTypeNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"PageLayoutNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"ApiKeysNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"ValueTypeNode",
"(",
")",
",",
"new",
"ConfigurationNode",
"\\",
"DebugNode",
"(",
")",
",",
"]",
";",
"}"
]
| Returns available configuration nodes for the bundle.
@return \Netgen\Bundle\BlockManagerBundle\DependencyInjection\ConfigurationNodeInterface[] | [
"Returns",
"available",
"configuration",
"nodes",
"for",
"the",
"bundle",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/Configuration.php#L47-L65 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/Handler/LayoutHandler.php | LayoutHandler.updateLayoutModifiedDate | private function updateLayoutModifiedDate(Layout $layout): void
{
$updatedLayout = clone $layout;
$updatedLayout->modified = time();
$this->queryHandler->updateLayout($updatedLayout);
} | php | private function updateLayoutModifiedDate(Layout $layout): void
{
$updatedLayout = clone $layout;
$updatedLayout->modified = time();
$this->queryHandler->updateLayout($updatedLayout);
} | [
"private",
"function",
"updateLayoutModifiedDate",
"(",
"Layout",
"$",
"layout",
")",
":",
"void",
"{",
"$",
"updatedLayout",
"=",
"clone",
"$",
"layout",
";",
"$",
"updatedLayout",
"->",
"modified",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"queryHandler",
"->",
"updateLayout",
"(",
"$",
"updatedLayout",
")",
";",
"}"
]
| Updates the layout modified date to the current timestamp. | [
"Updates",
"the",
"layout",
"modified",
"date",
"to",
"the",
"current",
"timestamp",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/Handler/LayoutHandler.php#L490-L495 | train |
netgen-layouts/layouts-core | lib/Collection/Result/Pagerfanta/ResultBuilderAdapter.php | ResultBuilderAdapter.setTotalCount | private function setTotalCount(ResultSet $result): void
{
$this->totalCount = $result->getTotalCount() - $this->startingOffset;
$this->totalCount = $this->totalCount > 0 ? $this->totalCount : 0;
if ($this->maxTotalCount !== null && $this->totalCount >= $this->maxTotalCount) {
$this->totalCount = $this->maxTotalCount;
}
} | php | private function setTotalCount(ResultSet $result): void
{
$this->totalCount = $result->getTotalCount() - $this->startingOffset;
$this->totalCount = $this->totalCount > 0 ? $this->totalCount : 0;
if ($this->maxTotalCount !== null && $this->totalCount >= $this->maxTotalCount) {
$this->totalCount = $this->maxTotalCount;
}
} | [
"private",
"function",
"setTotalCount",
"(",
"ResultSet",
"$",
"result",
")",
":",
"void",
"{",
"$",
"this",
"->",
"totalCount",
"=",
"$",
"result",
"->",
"getTotalCount",
"(",
")",
"-",
"$",
"this",
"->",
"startingOffset",
";",
"$",
"this",
"->",
"totalCount",
"=",
"$",
"this",
"->",
"totalCount",
">",
"0",
"?",
"$",
"this",
"->",
"totalCount",
":",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"maxTotalCount",
"!==",
"null",
"&&",
"$",
"this",
"->",
"totalCount",
">=",
"$",
"this",
"->",
"maxTotalCount",
")",
"{",
"$",
"this",
"->",
"totalCount",
"=",
"$",
"this",
"->",
"maxTotalCount",
";",
"}",
"}"
]
| Sets the total count of the results to the adapter, while taking into account
the injected maximum number of pages to use. | [
"Sets",
"the",
"total",
"count",
"of",
"the",
"results",
"to",
"the",
"adapter",
"while",
"taking",
"into",
"account",
"the",
"injected",
"maximum",
"number",
"of",
"pages",
"to",
"use",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Result/Pagerfanta/ResultBuilderAdapter.php#L88-L96 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/EventListener/ViewListener.php | ViewListener.onView | public function onView(GetResponseForControllerResultEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$controllerResult = $event->getControllerResult();
if (!$controllerResult instanceof ViewInterface) {
return;
}
$event->getRequest()->attributes->set('ngbmView', $controllerResult);
} | php | public function onView(GetResponseForControllerResultEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}
$controllerResult = $event->getControllerResult();
if (!$controllerResult instanceof ViewInterface) {
return;
}
$event->getRequest()->attributes->set('ngbmView', $controllerResult);
} | [
"public",
"function",
"onView",
"(",
"GetResponseForControllerResultEvent",
"$",
"event",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"controllerResult",
"=",
"$",
"event",
"->",
"getControllerResult",
"(",
")",
";",
"if",
"(",
"!",
"$",
"controllerResult",
"instanceof",
"ViewInterface",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"attributes",
"->",
"set",
"(",
"'ngbmView'",
",",
"$",
"controllerResult",
")",
";",
"}"
]
| Sets the Netgen Layouts view provided by the controller to the request. | [
"Sets",
"the",
"Netgen",
"Layouts",
"view",
"provided",
"by",
"the",
"controller",
"to",
"the",
"request",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/EventListener/ViewListener.php#L22-L34 | train |
netgen-layouts/layouts-core | lib/Transfer/Input/JsonValidator.php | JsonValidator.parseJson | private function parseJson(string $data): stdClass
{
$data = json_decode($data);
if ($data instanceof stdClass) {
return $data;
}
$errorCode = json_last_error();
if ($errorCode !== JSON_ERROR_NONE) {
throw JsonValidationException::parseError(json_last_error_msg(), $errorCode);
}
throw JsonValidationException::notAcceptable(
sprintf('Expected a JSON object, got %s', gettype($data))
);
} | php | private function parseJson(string $data): stdClass
{
$data = json_decode($data);
if ($data instanceof stdClass) {
return $data;
}
$errorCode = json_last_error();
if ($errorCode !== JSON_ERROR_NONE) {
throw JsonValidationException::parseError(json_last_error_msg(), $errorCode);
}
throw JsonValidationException::notAcceptable(
sprintf('Expected a JSON object, got %s', gettype($data))
);
} | [
"private",
"function",
"parseJson",
"(",
"string",
"$",
"data",
")",
":",
"stdClass",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"data",
"instanceof",
"stdClass",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"errorCode",
"=",
"json_last_error",
"(",
")",
";",
"if",
"(",
"$",
"errorCode",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"JsonValidationException",
"::",
"parseError",
"(",
"json_last_error_msg",
"(",
")",
",",
"$",
"errorCode",
")",
";",
"}",
"throw",
"JsonValidationException",
"::",
"notAcceptable",
"(",
"sprintf",
"(",
"'Expected a JSON object, got %s'",
",",
"gettype",
"(",
"$",
"data",
")",
")",
")",
";",
"}"
]
| Parses JSON data.
@throws \Netgen\BlockManager\Exception\Transfer\JsonValidationException | [
"Parses",
"JSON",
"data",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Transfer/Input/JsonValidator.php#L31-L48 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/ConfigStructBuilder.php | ConfigStructBuilder.buildConfigUpdateStructs | public function buildConfigUpdateStructs(ConfigAwareValue $configAwareValue, ConfigAwareStruct $configAwareStruct): void
{
foreach ($configAwareValue->getConfigs() as $configKey => $config) {
$configStruct = new ConfigStruct();
$configStruct->fillParametersFromConfig($config);
$configAwareStruct->setConfigStruct($configKey, $configStruct);
}
} | php | public function buildConfigUpdateStructs(ConfigAwareValue $configAwareValue, ConfigAwareStruct $configAwareStruct): void
{
foreach ($configAwareValue->getConfigs() as $configKey => $config) {
$configStruct = new ConfigStruct();
$configStruct->fillParametersFromConfig($config);
$configAwareStruct->setConfigStruct($configKey, $configStruct);
}
} | [
"public",
"function",
"buildConfigUpdateStructs",
"(",
"ConfigAwareValue",
"$",
"configAwareValue",
",",
"ConfigAwareStruct",
"$",
"configAwareStruct",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"configAwareValue",
"->",
"getConfigs",
"(",
")",
"as",
"$",
"configKey",
"=>",
"$",
"config",
")",
"{",
"$",
"configStruct",
"=",
"new",
"ConfigStruct",
"(",
")",
";",
"$",
"configStruct",
"->",
"fillParametersFromConfig",
"(",
"$",
"config",
")",
";",
"$",
"configAwareStruct",
"->",
"setConfigStruct",
"(",
"$",
"configKey",
",",
"$",
"configStruct",
")",
";",
"}",
"}"
]
| Fills the provided config aware struct with config structs, according to the provided value. | [
"Fills",
"the",
"provided",
"config",
"aware",
"struct",
"with",
"config",
"structs",
"according",
"to",
"the",
"provided",
"value",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/ConfigStructBuilder.php#L16-L23 | train |
netgen-layouts/layouts-core | lib/Item/ValueType/ValueTypeFactory.php | ValueTypeFactory.buildValueType | public static function buildValueType(string $identifier, array $config): ValueType
{
return ValueType::fromArray(
[
'identifier' => $identifier,
'isEnabled' => $config['enabled'],
'name' => $config['name'],
]
);
} | php | public static function buildValueType(string $identifier, array $config): ValueType
{
return ValueType::fromArray(
[
'identifier' => $identifier,
'isEnabled' => $config['enabled'],
'name' => $config['name'],
]
);
} | [
"public",
"static",
"function",
"buildValueType",
"(",
"string",
"$",
"identifier",
",",
"array",
"$",
"config",
")",
":",
"ValueType",
"{",
"return",
"ValueType",
"::",
"fromArray",
"(",
"[",
"'identifier'",
"=>",
"$",
"identifier",
",",
"'isEnabled'",
"=>",
"$",
"config",
"[",
"'enabled'",
"]",
",",
"'name'",
"=>",
"$",
"config",
"[",
"'name'",
"]",
",",
"]",
")",
";",
"}"
]
| Builds the value type. | [
"Builds",
"the",
"value",
"type",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Item/ValueType/ValueTypeFactory.php#L12-L21 | train |
netgen-layouts/layouts-core | lib/Collection/Item/VisibilityResolver.php | VisibilityResolver.setVoters | public function setVoters(array $voters): void
{
$this->voters = array_filter(
$voters,
static function (VisibilityVoterInterface $voter): bool {
return true;
}
);
} | php | public function setVoters(array $voters): void
{
$this->voters = array_filter(
$voters,
static function (VisibilityVoterInterface $voter): bool {
return true;
}
);
} | [
"public",
"function",
"setVoters",
"(",
"array",
"$",
"voters",
")",
":",
"void",
"{",
"$",
"this",
"->",
"voters",
"=",
"array_filter",
"(",
"$",
"voters",
",",
"static",
"function",
"(",
"VisibilityVoterInterface",
"$",
"voter",
")",
":",
"bool",
"{",
"return",
"true",
";",
"}",
")",
";",
"}"
]
| Sets the available voters.
@param \Netgen\BlockManager\Collection\Item\VisibilityVoterInterface[] $voters | [
"Sets",
"the",
"available",
"voters",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Collection/Item/VisibilityResolver.php#L21-L29 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.loadLayoutData | public function loadLayoutData($layoutId, int $status): array
{
$query = $this->getLayoutSelectQuery();
$query->where(
$query->expr()->eq('l.id', ':id')
)
->setParameter('id', $layoutId, Type::INTEGER);
$this->applyStatusCondition($query, $status, 'l.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadLayoutData($layoutId, int $status): array
{
$query = $this->getLayoutSelectQuery();
$query->where(
$query->expr()->eq('l.id', ':id')
)
->setParameter('id', $layoutId, Type::INTEGER);
$this->applyStatusCondition($query, $status, 'l.status');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadLayoutData",
"(",
"$",
"layoutId",
",",
"int",
"$",
"status",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getLayoutSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'l.id'",
",",
"':id'",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
",",
"'l.status'",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all data for layout with specified ID.
@param int|string $layoutId
@param int $status
@return array | [
"Loads",
"all",
"data",
"for",
"layout",
"with",
"specified",
"ID",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L25-L36 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.loadRelatedLayoutsData | public function loadRelatedLayoutsData(Layout $sharedLayout): array
{
$query = $this->getLayoutSelectQuery();
$query->innerJoin(
'l',
'ngbm_zone',
'z',
$query->expr()->andX(
$query->expr()->eq('z.layout_id', 'l.id'),
$query->expr()->eq('z.status', 'l.status'),
$query->expr()->eq('z.linked_layout_id', ':linked_layout_id')
)
)
->where(
$query->expr()->andX(
$query->expr()->eq('l.shared', ':shared'),
$query->expr()->eq('l.status', ':status')
)
)
->setParameter('shared', false, Type::BOOLEAN)
->setParameter('status', Value::STATUS_PUBLISHED, Type::INTEGER)
->setParameter('linked_layout_id', $sharedLayout->id, Type::INTEGER);
$query->orderBy('l.name', 'ASC');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadRelatedLayoutsData(Layout $sharedLayout): array
{
$query = $this->getLayoutSelectQuery();
$query->innerJoin(
'l',
'ngbm_zone',
'z',
$query->expr()->andX(
$query->expr()->eq('z.layout_id', 'l.id'),
$query->expr()->eq('z.status', 'l.status'),
$query->expr()->eq('z.linked_layout_id', ':linked_layout_id')
)
)
->where(
$query->expr()->andX(
$query->expr()->eq('l.shared', ':shared'),
$query->expr()->eq('l.status', ':status')
)
)
->setParameter('shared', false, Type::BOOLEAN)
->setParameter('status', Value::STATUS_PUBLISHED, Type::INTEGER)
->setParameter('linked_layout_id', $sharedLayout->id, Type::INTEGER);
$query->orderBy('l.name', 'ASC');
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadRelatedLayoutsData",
"(",
"Layout",
"$",
"sharedLayout",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getLayoutSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"innerJoin",
"(",
"'l'",
",",
"'ngbm_zone'",
",",
"'z'",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'z.layout_id'",
",",
"'l.id'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'z.status'",
",",
"'l.status'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'z.linked_layout_id'",
",",
"':linked_layout_id'",
")",
")",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'l.shared'",
",",
"':shared'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'l.status'",
",",
"':status'",
")",
")",
")",
"->",
"setParameter",
"(",
"'shared'",
",",
"false",
",",
"Type",
"::",
"BOOLEAN",
")",
"->",
"setParameter",
"(",
"'status'",
",",
"Value",
"::",
"STATUS_PUBLISHED",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'linked_layout_id'",
",",
"$",
"sharedLayout",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
";",
"$",
"query",
"->",
"orderBy",
"(",
"'l.name'",
",",
"'ASC'",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all data for layouts related to provided shared layout. | [
"Loads",
"all",
"data",
"for",
"layouts",
"related",
"to",
"provided",
"shared",
"layout",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L191-L218 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.getRelatedLayoutsCount | public function getRelatedLayoutsCount(Layout $sharedLayout): int
{
$query = $this->connection->createQueryBuilder();
$query->select('count(DISTINCT ngbm_layout.id) AS count')
->from('ngbm_layout')
->innerJoin(
'ngbm_layout',
'ngbm_zone',
'z',
$query->expr()->andX(
$query->expr()->eq('z.layout_id', 'ngbm_layout.id'),
$query->expr()->eq('z.status', 'ngbm_layout.status'),
$query->expr()->eq('z.linked_layout_id', ':linked_layout_id')
)
)
->where(
$query->expr()->andX(
$query->expr()->eq('ngbm_layout.shared', ':shared'),
$query->expr()->eq('ngbm_layout.status', ':status')
)
)
->setParameter('shared', false, Type::BOOLEAN)
->setParameter('status', Value::STATUS_PUBLISHED, Type::INTEGER)
->setParameter('linked_layout_id', $sharedLayout->id, Type::INTEGER);
$data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return (int) ($data[0]['count'] ?? 0);
} | php | public function getRelatedLayoutsCount(Layout $sharedLayout): int
{
$query = $this->connection->createQueryBuilder();
$query->select('count(DISTINCT ngbm_layout.id) AS count')
->from('ngbm_layout')
->innerJoin(
'ngbm_layout',
'ngbm_zone',
'z',
$query->expr()->andX(
$query->expr()->eq('z.layout_id', 'ngbm_layout.id'),
$query->expr()->eq('z.status', 'ngbm_layout.status'),
$query->expr()->eq('z.linked_layout_id', ':linked_layout_id')
)
)
->where(
$query->expr()->andX(
$query->expr()->eq('ngbm_layout.shared', ':shared'),
$query->expr()->eq('ngbm_layout.status', ':status')
)
)
->setParameter('shared', false, Type::BOOLEAN)
->setParameter('status', Value::STATUS_PUBLISHED, Type::INTEGER)
->setParameter('linked_layout_id', $sharedLayout->id, Type::INTEGER);
$data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return (int) ($data[0]['count'] ?? 0);
} | [
"public",
"function",
"getRelatedLayoutsCount",
"(",
"Layout",
"$",
"sharedLayout",
")",
":",
"int",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'count(DISTINCT ngbm_layout.id) AS count'",
")",
"->",
"from",
"(",
"'ngbm_layout'",
")",
"->",
"innerJoin",
"(",
"'ngbm_layout'",
",",
"'ngbm_zone'",
",",
"'z'",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'z.layout_id'",
",",
"'ngbm_layout.id'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'z.status'",
",",
"'ngbm_layout.status'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'z.linked_layout_id'",
",",
"':linked_layout_id'",
")",
")",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'ngbm_layout.shared'",
",",
"':shared'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'ngbm_layout.status'",
",",
"':status'",
")",
")",
")",
"->",
"setParameter",
"(",
"'shared'",
",",
"false",
",",
"Type",
"::",
"BOOLEAN",
")",
"->",
"setParameter",
"(",
"'status'",
",",
"Value",
"::",
"STATUS_PUBLISHED",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'linked_layout_id'",
",",
"$",
"sharedLayout",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
";",
"$",
"data",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"(",
"int",
")",
"(",
"$",
"data",
"[",
"0",
"]",
"[",
"'count'",
"]",
"??",
"0",
")",
";",
"}"
]
| Loads the count of layouts related to provided shared layout. | [
"Loads",
"the",
"count",
"of",
"layouts",
"related",
"to",
"provided",
"shared",
"layout",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L223-L251 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.loadZoneData | public function loadZoneData($layoutId, int $status, string $identifier): array
{
$query = $this->getZoneSelectQuery();
$query->where(
$query->expr()->andX(
$query->expr()->eq('layout_id', ':layout_id'),
$query->expr()->eq('identifier', ':identifier')
)
)
->setParameter('layout_id', $layoutId, Type::INTEGER)
->setParameter('identifier', $identifier, Type::STRING);
$this->applyStatusCondition($query, $status);
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadZoneData($layoutId, int $status, string $identifier): array
{
$query = $this->getZoneSelectQuery();
$query->where(
$query->expr()->andX(
$query->expr()->eq('layout_id', ':layout_id'),
$query->expr()->eq('identifier', ':identifier')
)
)
->setParameter('layout_id', $layoutId, Type::INTEGER)
->setParameter('identifier', $identifier, Type::STRING);
$this->applyStatusCondition($query, $status);
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadZoneData",
"(",
"$",
"layoutId",
",",
"int",
"$",
"status",
",",
"string",
"$",
"identifier",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getZoneSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'identifier'",
",",
"':identifier'",
")",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"identifier",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all zone data with provided identifier.
@param int|string $layoutId
@param int $status
@param string $identifier
@return array | [
"Loads",
"all",
"zone",
"data",
"with",
"provided",
"identifier",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L262-L277 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.loadLayoutZonesData | public function loadLayoutZonesData(Layout $layout): array
{
$query = $this->getZoneSelectQuery();
$query->where(
$query->expr()->eq('layout_id', ':layout_id')
)
->setParameter('layout_id', $layout->id, Type::INTEGER)
->orderBy('identifier', 'ASC');
$this->applyStatusCondition($query, $layout->status);
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | php | public function loadLayoutZonesData(Layout $layout): array
{
$query = $this->getZoneSelectQuery();
$query->where(
$query->expr()->eq('layout_id', ':layout_id')
)
->setParameter('layout_id', $layout->id, Type::INTEGER)
->orderBy('identifier', 'ASC');
$this->applyStatusCondition($query, $layout->status);
return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
} | [
"public",
"function",
"loadLayoutZonesData",
"(",
"Layout",
"$",
"layout",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getZoneSelectQuery",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layout",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"orderBy",
"(",
"'identifier'",
",",
"'ASC'",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"layout",
"->",
"status",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
]
| Loads all data for zones that belong to provided layout. | [
"Loads",
"all",
"data",
"for",
"zones",
"that",
"belong",
"to",
"provided",
"layout",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L282-L294 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.zoneExists | public function zoneExists($layoutId, int $status, string $identifier): bool
{
$query = $this->connection->createQueryBuilder();
$query->select('count(*) AS count')
->from('ngbm_zone')
->where(
$query->expr()->andX(
$query->expr()->eq('identifier', ':identifier'),
$query->expr()->eq('layout_id', ':layout_id')
)
)
->setParameter('identifier', $identifier, Type::STRING)
->setParameter('layout_id', $layoutId, Type::INTEGER);
$this->applyStatusCondition($query, $status);
$data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return (int) ($data[0]['count'] ?? 0) > 0;
} | php | public function zoneExists($layoutId, int $status, string $identifier): bool
{
$query = $this->connection->createQueryBuilder();
$query->select('count(*) AS count')
->from('ngbm_zone')
->where(
$query->expr()->andX(
$query->expr()->eq('identifier', ':identifier'),
$query->expr()->eq('layout_id', ':layout_id')
)
)
->setParameter('identifier', $identifier, Type::STRING)
->setParameter('layout_id', $layoutId, Type::INTEGER);
$this->applyStatusCondition($query, $status);
$data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return (int) ($data[0]['count'] ?? 0) > 0;
} | [
"public",
"function",
"zoneExists",
"(",
"$",
"layoutId",
",",
"int",
"$",
"status",
",",
"string",
"$",
"identifier",
")",
":",
"bool",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'count(*) AS count'",
")",
"->",
"from",
"(",
"'ngbm_zone'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'identifier'",
",",
"':identifier'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
")",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"identifier",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
")",
";",
"$",
"data",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"(",
"int",
")",
"(",
"$",
"data",
"[",
"0",
"]",
"[",
"'count'",
"]",
"??",
"0",
")",
">",
"0",
";",
"}"
]
| Returns if the zone exists.
@param int|string $layoutId
@param int $status
@param string $identifier
@return bool | [
"Returns",
"if",
"the",
"zone",
"exists",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L330-L349 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.layoutNameExists | public function layoutNameExists(string $name, $excludedLayoutId = null): bool
{
$query = $this->connection->createQueryBuilder();
$query->select('count(*) AS count')
->from('ngbm_layout')
->where(
$query->expr()->andX(
$query->expr()->eq('name', ':name')
)
)
->setParameter('name', trim($name), Type::STRING);
if ($excludedLayoutId !== null) {
$query->andWhere($query->expr()->neq('id', ':layout_id'))
->setParameter('layout_id', $excludedLayoutId, Type::INTEGER);
}
$data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return (int) ($data[0]['count'] ?? 0) > 0;
} | php | public function layoutNameExists(string $name, $excludedLayoutId = null): bool
{
$query = $this->connection->createQueryBuilder();
$query->select('count(*) AS count')
->from('ngbm_layout')
->where(
$query->expr()->andX(
$query->expr()->eq('name', ':name')
)
)
->setParameter('name', trim($name), Type::STRING);
if ($excludedLayoutId !== null) {
$query->andWhere($query->expr()->neq('id', ':layout_id'))
->setParameter('layout_id', $excludedLayoutId, Type::INTEGER);
}
$data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return (int) ($data[0]['count'] ?? 0) > 0;
} | [
"public",
"function",
"layoutNameExists",
"(",
"string",
"$",
"name",
",",
"$",
"excludedLayoutId",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'count(*) AS count'",
")",
"->",
"from",
"(",
"'ngbm_layout'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'name'",
",",
"':name'",
")",
")",
")",
"->",
"setParameter",
"(",
"'name'",
",",
"trim",
"(",
"$",
"name",
")",
",",
"Type",
"::",
"STRING",
")",
";",
"if",
"(",
"$",
"excludedLayoutId",
"!==",
"null",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"neq",
"(",
"'id'",
",",
"':layout_id'",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"excludedLayoutId",
",",
"Type",
"::",
"INTEGER",
")",
";",
"}",
"$",
"data",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"(",
"int",
")",
"(",
"$",
"data",
"[",
"0",
"]",
"[",
"'count'",
"]",
"??",
"0",
")",
">",
"0",
";",
"}"
]
| Returns if the layout with provided name exists.
@param string $name
@param int|string $excludedLayoutId
@return bool | [
"Returns",
"if",
"the",
"layout",
"with",
"provided",
"name",
"exists",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L359-L379 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.createLayout | public function createLayout(Layout $layout): Layout
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_layout')
->values(
[
'id' => ':id',
'status' => ':status',
'type' => ':type',
'name' => ':name',
'description' => ':description',
'created' => ':created',
'modified' => ':modified',
'shared' => ':shared',
'main_locale' => ':main_locale',
]
)
->setValue(
'id',
$layout->id !== null ?
(int) $layout->id :
$this->connectionHelper->getAutoIncrementValue('ngbm_layout')
)
->setParameter('status', $layout->status, Type::INTEGER)
->setParameter('type', $layout->type, Type::STRING)
->setParameter('name', $layout->name, Type::STRING)
->setParameter('description', $layout->description, Type::STRING)
->setParameter('created', $layout->created, Type::INTEGER)
->setParameter('modified', $layout->modified, Type::INTEGER)
->setParameter('shared', $layout->shared, Type::BOOLEAN)
->setParameter('main_locale', $layout->mainLocale, Type::STRING);
$query->execute();
$layout->id = $layout->id ?? (int) $this->connectionHelper->lastInsertId('ngbm_layout');
return $layout;
} | php | public function createLayout(Layout $layout): Layout
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_layout')
->values(
[
'id' => ':id',
'status' => ':status',
'type' => ':type',
'name' => ':name',
'description' => ':description',
'created' => ':created',
'modified' => ':modified',
'shared' => ':shared',
'main_locale' => ':main_locale',
]
)
->setValue(
'id',
$layout->id !== null ?
(int) $layout->id :
$this->connectionHelper->getAutoIncrementValue('ngbm_layout')
)
->setParameter('status', $layout->status, Type::INTEGER)
->setParameter('type', $layout->type, Type::STRING)
->setParameter('name', $layout->name, Type::STRING)
->setParameter('description', $layout->description, Type::STRING)
->setParameter('created', $layout->created, Type::INTEGER)
->setParameter('modified', $layout->modified, Type::INTEGER)
->setParameter('shared', $layout->shared, Type::BOOLEAN)
->setParameter('main_locale', $layout->mainLocale, Type::STRING);
$query->execute();
$layout->id = $layout->id ?? (int) $this->connectionHelper->lastInsertId('ngbm_layout');
return $layout;
} | [
"public",
"function",
"createLayout",
"(",
"Layout",
"$",
"layout",
")",
":",
"Layout",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"insert",
"(",
"'ngbm_layout'",
")",
"->",
"values",
"(",
"[",
"'id'",
"=>",
"':id'",
",",
"'status'",
"=>",
"':status'",
",",
"'type'",
"=>",
"':type'",
",",
"'name'",
"=>",
"':name'",
",",
"'description'",
"=>",
"':description'",
",",
"'created'",
"=>",
"':created'",
",",
"'modified'",
"=>",
"':modified'",
",",
"'shared'",
"=>",
"':shared'",
",",
"'main_locale'",
"=>",
"':main_locale'",
",",
"]",
")",
"->",
"setValue",
"(",
"'id'",
",",
"$",
"layout",
"->",
"id",
"!==",
"null",
"?",
"(",
"int",
")",
"$",
"layout",
"->",
"id",
":",
"$",
"this",
"->",
"connectionHelper",
"->",
"getAutoIncrementValue",
"(",
"'ngbm_layout'",
")",
")",
"->",
"setParameter",
"(",
"'status'",
",",
"$",
"layout",
"->",
"status",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'type'",
",",
"$",
"layout",
"->",
"type",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'name'",
",",
"$",
"layout",
"->",
"name",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'description'",
",",
"$",
"layout",
"->",
"description",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'created'",
",",
"$",
"layout",
"->",
"created",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'modified'",
",",
"$",
"layout",
"->",
"modified",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'shared'",
",",
"$",
"layout",
"->",
"shared",
",",
"Type",
"::",
"BOOLEAN",
")",
"->",
"setParameter",
"(",
"'main_locale'",
",",
"$",
"layout",
"->",
"mainLocale",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"layout",
"->",
"id",
"=",
"$",
"layout",
"->",
"id",
"??",
"(",
"int",
")",
"$",
"this",
"->",
"connectionHelper",
"->",
"lastInsertId",
"(",
"'ngbm_layout'",
")",
";",
"return",
"$",
"layout",
";",
"}"
]
| Creates a layout. | [
"Creates",
"a",
"layout",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L384-L421 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.createLayoutTranslation | public function createLayoutTranslation(Layout $layout, string $locale): void
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_layout_translation')
->values(
[
'layout_id' => ':layout_id',
'status' => ':status',
'locale' => ':locale',
]
)
->setParameter('layout_id', $layout->id, Type::INTEGER)
->setParameter('status', $layout->status, Type::INTEGER)
->setParameter('locale', $locale, Type::STRING);
$query->execute();
} | php | public function createLayoutTranslation(Layout $layout, string $locale): void
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_layout_translation')
->values(
[
'layout_id' => ':layout_id',
'status' => ':status',
'locale' => ':locale',
]
)
->setParameter('layout_id', $layout->id, Type::INTEGER)
->setParameter('status', $layout->status, Type::INTEGER)
->setParameter('locale', $locale, Type::STRING);
$query->execute();
} | [
"public",
"function",
"createLayoutTranslation",
"(",
"Layout",
"$",
"layout",
",",
"string",
"$",
"locale",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"insert",
"(",
"'ngbm_layout_translation'",
")",
"->",
"values",
"(",
"[",
"'layout_id'",
"=>",
"':layout_id'",
",",
"'status'",
"=>",
"':status'",
",",
"'locale'",
"=>",
"':locale'",
",",
"]",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layout",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'status'",
",",
"$",
"layout",
"->",
"status",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Creates a layout translation. | [
"Creates",
"a",
"layout",
"translation",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L426-L442 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.createZone | public function createZone(Zone $zone): void
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_zone')
->values(
[
'identifier' => ':identifier',
'layout_id' => ':layout_id',
'status' => ':status',
'root_block_id' => ':root_block_id',
'linked_layout_id' => ':linked_layout_id',
'linked_zone_identifier' => ':linked_zone_identifier',
]
)
->setParameter('identifier', $zone->identifier, Type::STRING)
->setParameter('layout_id', $zone->layoutId, Type::INTEGER)
->setParameter('status', $zone->status, Type::INTEGER)
->setParameter('root_block_id', $zone->rootBlockId, Type::INTEGER)
->setParameter('linked_layout_id', $zone->linkedLayoutId, Type::INTEGER)
->setParameter('linked_zone_identifier', $zone->linkedZoneIdentifier, Type::STRING);
$query->execute();
} | php | public function createZone(Zone $zone): void
{
$query = $this->connection->createQueryBuilder()
->insert('ngbm_zone')
->values(
[
'identifier' => ':identifier',
'layout_id' => ':layout_id',
'status' => ':status',
'root_block_id' => ':root_block_id',
'linked_layout_id' => ':linked_layout_id',
'linked_zone_identifier' => ':linked_zone_identifier',
]
)
->setParameter('identifier', $zone->identifier, Type::STRING)
->setParameter('layout_id', $zone->layoutId, Type::INTEGER)
->setParameter('status', $zone->status, Type::INTEGER)
->setParameter('root_block_id', $zone->rootBlockId, Type::INTEGER)
->setParameter('linked_layout_id', $zone->linkedLayoutId, Type::INTEGER)
->setParameter('linked_zone_identifier', $zone->linkedZoneIdentifier, Type::STRING);
$query->execute();
} | [
"public",
"function",
"createZone",
"(",
"Zone",
"$",
"zone",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"insert",
"(",
"'ngbm_zone'",
")",
"->",
"values",
"(",
"[",
"'identifier'",
"=>",
"':identifier'",
",",
"'layout_id'",
"=>",
"':layout_id'",
",",
"'status'",
"=>",
"':status'",
",",
"'root_block_id'",
"=>",
"':root_block_id'",
",",
"'linked_layout_id'",
"=>",
"':linked_layout_id'",
",",
"'linked_zone_identifier'",
"=>",
"':linked_zone_identifier'",
",",
"]",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"zone",
"->",
"identifier",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"zone",
"->",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'status'",
",",
"$",
"zone",
"->",
"status",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'root_block_id'",
",",
"$",
"zone",
"->",
"rootBlockId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'linked_layout_id'",
",",
"$",
"zone",
"->",
"linkedLayoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'linked_zone_identifier'",
",",
"$",
"zone",
"->",
"linkedZoneIdentifier",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Creates a zone. | [
"Creates",
"a",
"zone",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L447-L469 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.updateLayout | public function updateLayout(Layout $layout): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_layout')
->set('type', ':type')
->set('name', ':name')
->set('description', ':description')
->set('created', ':created')
->set('modified', ':modified')
->set('shared', ':shared')
->set('main_locale', ':main_locale')
->where(
$query->expr()->eq('id', ':id')
)
->setParameter('id', $layout->id, Type::INTEGER)
->setParameter('type', $layout->type, Type::STRING)
->setParameter('name', $layout->name, Type::STRING)
->setParameter('description', $layout->description, Type::STRING)
->setParameter('created', $layout->created, Type::INTEGER)
->setParameter('modified', $layout->modified, Type::INTEGER)
->setParameter('shared', $layout->shared, Type::BOOLEAN)
->setParameter('main_locale', $layout->mainLocale, Type::STRING);
$this->applyStatusCondition($query, $layout->status);
$query->execute();
} | php | public function updateLayout(Layout $layout): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_layout')
->set('type', ':type')
->set('name', ':name')
->set('description', ':description')
->set('created', ':created')
->set('modified', ':modified')
->set('shared', ':shared')
->set('main_locale', ':main_locale')
->where(
$query->expr()->eq('id', ':id')
)
->setParameter('id', $layout->id, Type::INTEGER)
->setParameter('type', $layout->type, Type::STRING)
->setParameter('name', $layout->name, Type::STRING)
->setParameter('description', $layout->description, Type::STRING)
->setParameter('created', $layout->created, Type::INTEGER)
->setParameter('modified', $layout->modified, Type::INTEGER)
->setParameter('shared', $layout->shared, Type::BOOLEAN)
->setParameter('main_locale', $layout->mainLocale, Type::STRING);
$this->applyStatusCondition($query, $layout->status);
$query->execute();
} | [
"public",
"function",
"updateLayout",
"(",
"Layout",
"$",
"layout",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"update",
"(",
"'ngbm_layout'",
")",
"->",
"set",
"(",
"'type'",
",",
"':type'",
")",
"->",
"set",
"(",
"'name'",
",",
"':name'",
")",
"->",
"set",
"(",
"'description'",
",",
"':description'",
")",
"->",
"set",
"(",
"'created'",
",",
"':created'",
")",
"->",
"set",
"(",
"'modified'",
",",
"':modified'",
")",
"->",
"set",
"(",
"'shared'",
",",
"':shared'",
")",
"->",
"set",
"(",
"'main_locale'",
",",
"':main_locale'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'id'",
",",
"':id'",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"layout",
"->",
"id",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'type'",
",",
"$",
"layout",
"->",
"type",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'name'",
",",
"$",
"layout",
"->",
"name",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'description'",
",",
"$",
"layout",
"->",
"description",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'created'",
",",
"$",
"layout",
"->",
"created",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'modified'",
",",
"$",
"layout",
"->",
"modified",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'shared'",
",",
"$",
"layout",
"->",
"shared",
",",
"Type",
"::",
"BOOLEAN",
")",
"->",
"setParameter",
"(",
"'main_locale'",
",",
"$",
"layout",
"->",
"mainLocale",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"layout",
"->",
"status",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Updates a layout. | [
"Updates",
"a",
"layout",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L474-L501 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.updateZone | public function updateZone(Zone $zone): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_zone')
->set('root_block_id', ':root_block_id')
->set('linked_layout_id', ':linked_layout_id')
->set('linked_zone_identifier', ':linked_zone_identifier')
->where(
$query->expr()->andX(
$query->expr()->eq('layout_id', ':layout_id'),
$query->expr()->eq('identifier', ':identifier')
)
)
->setParameter('layout_id', $zone->layoutId, Type::INTEGER)
->setParameter('identifier', $zone->identifier, Type::STRING)
->setParameter('root_block_id', $zone->rootBlockId, Type::INTEGER)
->setParameter('linked_layout_id', $zone->linkedLayoutId, Type::INTEGER)
->setParameter('linked_zone_identifier', $zone->linkedZoneIdentifier, Type::STRING);
$this->applyStatusCondition($query, $zone->status);
$query->execute();
} | php | public function updateZone(Zone $zone): void
{
$query = $this->connection->createQueryBuilder();
$query
->update('ngbm_zone')
->set('root_block_id', ':root_block_id')
->set('linked_layout_id', ':linked_layout_id')
->set('linked_zone_identifier', ':linked_zone_identifier')
->where(
$query->expr()->andX(
$query->expr()->eq('layout_id', ':layout_id'),
$query->expr()->eq('identifier', ':identifier')
)
)
->setParameter('layout_id', $zone->layoutId, Type::INTEGER)
->setParameter('identifier', $zone->identifier, Type::STRING)
->setParameter('root_block_id', $zone->rootBlockId, Type::INTEGER)
->setParameter('linked_layout_id', $zone->linkedLayoutId, Type::INTEGER)
->setParameter('linked_zone_identifier', $zone->linkedZoneIdentifier, Type::STRING);
$this->applyStatusCondition($query, $zone->status);
$query->execute();
} | [
"public",
"function",
"updateZone",
"(",
"Zone",
"$",
"zone",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"update",
"(",
"'ngbm_zone'",
")",
"->",
"set",
"(",
"'root_block_id'",
",",
"':root_block_id'",
")",
"->",
"set",
"(",
"'linked_layout_id'",
",",
"':linked_layout_id'",
")",
"->",
"set",
"(",
"'linked_zone_identifier'",
",",
"':linked_zone_identifier'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'identifier'",
",",
"':identifier'",
")",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"zone",
"->",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"zone",
"->",
"identifier",
",",
"Type",
"::",
"STRING",
")",
"->",
"setParameter",
"(",
"'root_block_id'",
",",
"$",
"zone",
"->",
"rootBlockId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'linked_layout_id'",
",",
"$",
"zone",
"->",
"linkedLayoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'linked_zone_identifier'",
",",
"$",
"zone",
"->",
"linkedZoneIdentifier",
",",
"Type",
"::",
"STRING",
")",
";",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"zone",
"->",
"status",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Updates a zone. | [
"Updates",
"a",
"zone",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L506-L529 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.deleteLayoutZones | public function deleteLayoutZones($layoutId, ?int $status = null): void
{
$query = $this->connection->createQueryBuilder();
$query->delete('ngbm_zone')
->where(
$query->expr()->eq('layout_id', ':layout_id')
)
->setParameter('layout_id', $layoutId, Type::INTEGER);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$query->execute();
} | php | public function deleteLayoutZones($layoutId, ?int $status = null): void
{
$query = $this->connection->createQueryBuilder();
$query->delete('ngbm_zone')
->where(
$query->expr()->eq('layout_id', ':layout_id')
)
->setParameter('layout_id', $layoutId, Type::INTEGER);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$query->execute();
} | [
"public",
"function",
"deleteLayoutZones",
"(",
"$",
"layoutId",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"delete",
"(",
"'ngbm_zone'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
")",
";",
"}",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Deletes all layout zones.
@param int|string $layoutId
@param int $status | [
"Deletes",
"all",
"layout",
"zones",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L537-L551 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.deleteZone | public function deleteZone($layoutId, string $zoneIdentifier, ?int $status = null): void
{
$query = $this->connection->createQueryBuilder();
$query->delete('ngbm_zone')
->where(
$query->expr()->andX(
$query->expr()->eq('layout_id', ':layout_id'),
$query->expr()->eq('identifier', ':identifier')
)
)
->setParameter('layout_id', $layoutId, Type::INTEGER)
->setParameter('identifier', $zoneIdentifier, Type::STRING);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$query->execute();
} | php | public function deleteZone($layoutId, string $zoneIdentifier, ?int $status = null): void
{
$query = $this->connection->createQueryBuilder();
$query->delete('ngbm_zone')
->where(
$query->expr()->andX(
$query->expr()->eq('layout_id', ':layout_id'),
$query->expr()->eq('identifier', ':identifier')
)
)
->setParameter('layout_id', $layoutId, Type::INTEGER)
->setParameter('identifier', $zoneIdentifier, Type::STRING);
if ($status !== null) {
$this->applyStatusCondition($query, $status);
}
$query->execute();
} | [
"public",
"function",
"deleteZone",
"(",
"$",
"layoutId",
",",
"string",
"$",
"zoneIdentifier",
",",
"?",
"int",
"$",
"status",
"=",
"null",
")",
":",
"void",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"delete",
"(",
"'ngbm_zone'",
")",
"->",
"where",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'layout_id'",
",",
"':layout_id'",
")",
",",
"$",
"query",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'identifier'",
",",
"':identifier'",
")",
")",
")",
"->",
"setParameter",
"(",
"'layout_id'",
",",
"$",
"layoutId",
",",
"Type",
"::",
"INTEGER",
")",
"->",
"setParameter",
"(",
"'identifier'",
",",
"$",
"zoneIdentifier",
",",
"Type",
"::",
"STRING",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"applyStatusCondition",
"(",
"$",
"query",
",",
"$",
"status",
")",
";",
"}",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}"
]
| Deletes the zone.
@param int|string $layoutId
@param string $zoneIdentifier
@param int $status | [
"Deletes",
"the",
"zone",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L582-L600 | train |
netgen-layouts/layouts-core | lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php | LayoutQueryHandler.getZoneSelectQuery | private function getZoneSelectQuery(): QueryBuilder
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT ngbm_zone.*')
->from('ngbm_zone');
return $query;
} | php | private function getZoneSelectQuery(): QueryBuilder
{
$query = $this->connection->createQueryBuilder();
$query->select('DISTINCT ngbm_zone.*')
->from('ngbm_zone');
return $query;
} | [
"private",
"function",
"getZoneSelectQuery",
"(",
")",
":",
"QueryBuilder",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'DISTINCT ngbm_zone.*'",
")",
"->",
"from",
"(",
"'ngbm_zone'",
")",
";",
"return",
"$",
"query",
";",
"}"
]
| Builds and returns a zone database SELECT query. | [
"Builds",
"and",
"returns",
"a",
"zone",
"database",
"SELECT",
"query",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Persistence/Doctrine/QueryHandler/LayoutQueryHandler.php#L656-L663 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Controller/API/V1/BlockCollection/AddItems.php | AddItems.validateAddItems | private function validateAddItems(Block $block, string $collectionIdentifier, $items): void
{
$this->validate(
$items,
[
new Constraints\Type(['type' => 'array']),
new Constraints\NotBlank(),
new Constraints\All(
[
'constraints' => new Constraints\Collection(
[
'fields' => [
'value' => [
new Constraints\NotNull(),
new Constraints\Type(['type' => 'scalar']),
],
'value_type' => [
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'string']),
],
'position' => new Constraints\Optional(
[
new Constraints\NotNull(),
new Constraints\Type(['type' => 'int']),
]
),
],
]
),
]
),
],
'items'
);
$blockDefinition = $block->getDefinition();
if (!$blockDefinition->hasCollection($collectionIdentifier)) {
return;
}
$collectionConfig = $blockDefinition->getCollection($collectionIdentifier);
foreach ($items as $item) {
if (!$collectionConfig->isValidItemType($item['value_type'])) {
throw ValidationException::validationFailed(
'value_type',
sprintf(
'Value type "%s" is not allowed in selected block.',
$item['value_type']
)
);
}
}
} | php | private function validateAddItems(Block $block, string $collectionIdentifier, $items): void
{
$this->validate(
$items,
[
new Constraints\Type(['type' => 'array']),
new Constraints\NotBlank(),
new Constraints\All(
[
'constraints' => new Constraints\Collection(
[
'fields' => [
'value' => [
new Constraints\NotNull(),
new Constraints\Type(['type' => 'scalar']),
],
'value_type' => [
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'string']),
],
'position' => new Constraints\Optional(
[
new Constraints\NotNull(),
new Constraints\Type(['type' => 'int']),
]
),
],
]
),
]
),
],
'items'
);
$blockDefinition = $block->getDefinition();
if (!$blockDefinition->hasCollection($collectionIdentifier)) {
return;
}
$collectionConfig = $blockDefinition->getCollection($collectionIdentifier);
foreach ($items as $item) {
if (!$collectionConfig->isValidItemType($item['value_type'])) {
throw ValidationException::validationFailed(
'value_type',
sprintf(
'Value type "%s" is not allowed in selected block.',
$item['value_type']
)
);
}
}
} | [
"private",
"function",
"validateAddItems",
"(",
"Block",
"$",
"block",
",",
"string",
"$",
"collectionIdentifier",
",",
"$",
"items",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"items",
",",
"[",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'array'",
"]",
")",
",",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"All",
"(",
"[",
"'constraints'",
"=>",
"new",
"Constraints",
"\\",
"Collection",
"(",
"[",
"'fields'",
"=>",
"[",
"'value'",
"=>",
"[",
"new",
"Constraints",
"\\",
"NotNull",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'scalar'",
"]",
")",
",",
"]",
",",
"'value_type'",
"=>",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'string'",
"]",
")",
",",
"]",
",",
"'position'",
"=>",
"new",
"Constraints",
"\\",
"Optional",
"(",
"[",
"new",
"Constraints",
"\\",
"NotNull",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'int'",
"]",
")",
",",
"]",
")",
",",
"]",
",",
"]",
")",
",",
"]",
")",
",",
"]",
",",
"'items'",
")",
";",
"$",
"blockDefinition",
"=",
"$",
"block",
"->",
"getDefinition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"blockDefinition",
"->",
"hasCollection",
"(",
"$",
"collectionIdentifier",
")",
")",
"{",
"return",
";",
"}",
"$",
"collectionConfig",
"=",
"$",
"blockDefinition",
"->",
"getCollection",
"(",
"$",
"collectionIdentifier",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"collectionConfig",
"->",
"isValidItemType",
"(",
"$",
"item",
"[",
"'value_type'",
"]",
")",
")",
"{",
"throw",
"ValidationException",
"::",
"validationFailed",
"(",
"'value_type'",
",",
"sprintf",
"(",
"'Value type \"%s\" is not allowed in selected block.'",
",",
"$",
"item",
"[",
"'value_type'",
"]",
")",
")",
";",
"}",
"}",
"}"
]
| Validates item creation parameters from the request.
@param \Netgen\BlockManager\API\Values\Block\Block $block
@param string $collectionIdentifier
@param mixed $items | [
"Validates",
"item",
"creation",
"parameters",
"from",
"the",
"request",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Controller/API/V1/BlockCollection/AddItems.php#L77-L130 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Controller/API/V1/Layout/Create.php | Create.validateCreateLayout | private function validateCreateLayout(ParameterBag $data): void
{
$this->validate(
$data->get('layout_type'),
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'string']),
],
'layout_type'
);
$this->validate(
$data->get('locale'),
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'string']),
new LocaleConstraint(),
],
'locale'
);
} | php | private function validateCreateLayout(ParameterBag $data): void
{
$this->validate(
$data->get('layout_type'),
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'string']),
],
'layout_type'
);
$this->validate(
$data->get('locale'),
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'string']),
new LocaleConstraint(),
],
'locale'
);
} | [
"private",
"function",
"validateCreateLayout",
"(",
"ParameterBag",
"$",
"data",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"data",
"->",
"get",
"(",
"'layout_type'",
")",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'string'",
"]",
")",
",",
"]",
",",
"'layout_type'",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"data",
"->",
"get",
"(",
"'locale'",
")",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'string'",
"]",
")",
",",
"new",
"LocaleConstraint",
"(",
")",
",",
"]",
",",
"'locale'",
")",
";",
"}"
]
| Validates layout creation parameters from the request.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If validation failed | [
"Validates",
"layout",
"creation",
"parameters",
"from",
"the",
"request",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Controller/API/V1/Layout/Create.php#L80-L100 | train |
netgen-layouts/layouts-core | lib/Core/Validator/CollectionValidator.php | CollectionValidator.validateCollectionCreateStruct | public function validateCollectionCreateStruct(CollectionCreateStruct $collectionCreateStruct): void
{
if ($collectionCreateStruct->queryCreateStruct !== null) {
$this->validate(
$collectionCreateStruct->queryCreateStruct,
[
new Constraints\Type(['type' => QueryCreateStruct::class]),
],
'queryCreateStruct'
);
$this->validateQueryCreateStruct($collectionCreateStruct->queryCreateStruct);
}
$offsetConstraints = [
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'int']),
];
$offsetConstraints[] = $collectionCreateStruct->queryCreateStruct !== null ?
new Constraints\GreaterThanOrEqual(['value' => 0]) :
new Constraints\EqualTo(['value' => 0]);
$this->validate(
$collectionCreateStruct->offset,
$offsetConstraints,
'offset'
);
if ($collectionCreateStruct->limit !== null) {
$this->validate(
$collectionCreateStruct->limit,
[
new Constraints\Type(['type' => 'int']),
new Constraints\GreaterThan(['value' => 0]),
],
'limit'
);
}
} | php | public function validateCollectionCreateStruct(CollectionCreateStruct $collectionCreateStruct): void
{
if ($collectionCreateStruct->queryCreateStruct !== null) {
$this->validate(
$collectionCreateStruct->queryCreateStruct,
[
new Constraints\Type(['type' => QueryCreateStruct::class]),
],
'queryCreateStruct'
);
$this->validateQueryCreateStruct($collectionCreateStruct->queryCreateStruct);
}
$offsetConstraints = [
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'int']),
];
$offsetConstraints[] = $collectionCreateStruct->queryCreateStruct !== null ?
new Constraints\GreaterThanOrEqual(['value' => 0]) :
new Constraints\EqualTo(['value' => 0]);
$this->validate(
$collectionCreateStruct->offset,
$offsetConstraints,
'offset'
);
if ($collectionCreateStruct->limit !== null) {
$this->validate(
$collectionCreateStruct->limit,
[
new Constraints\Type(['type' => 'int']),
new Constraints\GreaterThan(['value' => 0]),
],
'limit'
);
}
} | [
"public",
"function",
"validateCollectionCreateStruct",
"(",
"CollectionCreateStruct",
"$",
"collectionCreateStruct",
")",
":",
"void",
"{",
"if",
"(",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
",",
"[",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"QueryCreateStruct",
"::",
"class",
"]",
")",
",",
"]",
",",
"'queryCreateStruct'",
")",
";",
"$",
"this",
"->",
"validateQueryCreateStruct",
"(",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
")",
";",
"}",
"$",
"offsetConstraints",
"=",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'int'",
"]",
")",
",",
"]",
";",
"$",
"offsetConstraints",
"[",
"]",
"=",
"$",
"collectionCreateStruct",
"->",
"queryCreateStruct",
"!==",
"null",
"?",
"new",
"Constraints",
"\\",
"GreaterThanOrEqual",
"(",
"[",
"'value'",
"=>",
"0",
"]",
")",
":",
"new",
"Constraints",
"\\",
"EqualTo",
"(",
"[",
"'value'",
"=>",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"collectionCreateStruct",
"->",
"offset",
",",
"$",
"offsetConstraints",
",",
"'offset'",
")",
";",
"if",
"(",
"$",
"collectionCreateStruct",
"->",
"limit",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"collectionCreateStruct",
"->",
"limit",
",",
"[",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'int'",
"]",
")",
",",
"new",
"Constraints",
"\\",
"GreaterThan",
"(",
"[",
"'value'",
"=>",
"0",
"]",
")",
",",
"]",
",",
"'limit'",
")",
";",
"}",
"}"
]
| Validates the provided collection create struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"collection",
"create",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/CollectionValidator.php#L29-L68 | train |
netgen-layouts/layouts-core | lib/Core/Validator/CollectionValidator.php | CollectionValidator.validateCollectionUpdateStruct | public function validateCollectionUpdateStruct(Collection $collection, CollectionUpdateStruct $collectionUpdateStruct): void
{
if ($collectionUpdateStruct->offset !== null) {
$offsetConstraints = [
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'int']),
];
$offsetConstraints[] = $collection->hasQuery() ?
new Constraints\GreaterThanOrEqual(['value' => 0]) :
new Constraints\EqualTo(['value' => 0]);
$this->validate(
$collectionUpdateStruct->offset,
$offsetConstraints,
'offset'
);
}
if ($collectionUpdateStruct->limit !== null) {
$this->validate(
$collectionUpdateStruct->limit,
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'int']),
new Constraints\GreaterThanOrEqual(['value' => 0]),
],
'limit'
);
}
} | php | public function validateCollectionUpdateStruct(Collection $collection, CollectionUpdateStruct $collectionUpdateStruct): void
{
if ($collectionUpdateStruct->offset !== null) {
$offsetConstraints = [
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'int']),
];
$offsetConstraints[] = $collection->hasQuery() ?
new Constraints\GreaterThanOrEqual(['value' => 0]) :
new Constraints\EqualTo(['value' => 0]);
$this->validate(
$collectionUpdateStruct->offset,
$offsetConstraints,
'offset'
);
}
if ($collectionUpdateStruct->limit !== null) {
$this->validate(
$collectionUpdateStruct->limit,
[
new Constraints\NotBlank(),
new Constraints\Type(['type' => 'int']),
new Constraints\GreaterThanOrEqual(['value' => 0]),
],
'limit'
);
}
} | [
"public",
"function",
"validateCollectionUpdateStruct",
"(",
"Collection",
"$",
"collection",
",",
"CollectionUpdateStruct",
"$",
"collectionUpdateStruct",
")",
":",
"void",
"{",
"if",
"(",
"$",
"collectionUpdateStruct",
"->",
"offset",
"!==",
"null",
")",
"{",
"$",
"offsetConstraints",
"=",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'int'",
"]",
")",
",",
"]",
";",
"$",
"offsetConstraints",
"[",
"]",
"=",
"$",
"collection",
"->",
"hasQuery",
"(",
")",
"?",
"new",
"Constraints",
"\\",
"GreaterThanOrEqual",
"(",
"[",
"'value'",
"=>",
"0",
"]",
")",
":",
"new",
"Constraints",
"\\",
"EqualTo",
"(",
"[",
"'value'",
"=>",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"collectionUpdateStruct",
"->",
"offset",
",",
"$",
"offsetConstraints",
",",
"'offset'",
")",
";",
"}",
"if",
"(",
"$",
"collectionUpdateStruct",
"->",
"limit",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"collectionUpdateStruct",
"->",
"limit",
",",
"[",
"new",
"Constraints",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'int'",
"]",
")",
",",
"new",
"Constraints",
"\\",
"GreaterThanOrEqual",
"(",
"[",
"'value'",
"=>",
"0",
"]",
")",
",",
"]",
",",
"'limit'",
")",
";",
"}",
"}"
]
| Validates the provided collection update struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"collection",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/CollectionValidator.php#L75-L105 | train |
netgen-layouts/layouts-core | lib/Core/Validator/CollectionValidator.php | CollectionValidator.validateItemCreateStruct | public function validateItemCreateStruct(ItemCreateStruct $itemCreateStruct): void
{
$this->validate(
$itemCreateStruct->definition,
[
new Constraints\NotNull(),
new Constraints\Type(['type' => ItemDefinitionInterface::class]),
],
'definition'
);
if ($itemCreateStruct->value !== null) {
$this->validate(
$itemCreateStruct->value,
[
new Constraints\Type(['type' => 'scalar']),
],
'value'
);
}
$this->validate(
$itemCreateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $itemCreateStruct->definition,
]
)
);
} | php | public function validateItemCreateStruct(ItemCreateStruct $itemCreateStruct): void
{
$this->validate(
$itemCreateStruct->definition,
[
new Constraints\NotNull(),
new Constraints\Type(['type' => ItemDefinitionInterface::class]),
],
'definition'
);
if ($itemCreateStruct->value !== null) {
$this->validate(
$itemCreateStruct->value,
[
new Constraints\Type(['type' => 'scalar']),
],
'value'
);
}
$this->validate(
$itemCreateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $itemCreateStruct->definition,
]
)
);
} | [
"public",
"function",
"validateItemCreateStruct",
"(",
"ItemCreateStruct",
"$",
"itemCreateStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"itemCreateStruct",
"->",
"definition",
",",
"[",
"new",
"Constraints",
"\\",
"NotNull",
"(",
")",
",",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"ItemDefinitionInterface",
"::",
"class",
"]",
")",
",",
"]",
",",
"'definition'",
")",
";",
"if",
"(",
"$",
"itemCreateStruct",
"->",
"value",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"itemCreateStruct",
"->",
"value",
",",
"[",
"new",
"Constraints",
"\\",
"Type",
"(",
"[",
"'type'",
"=>",
"'scalar'",
"]",
")",
",",
"]",
",",
"'value'",
")",
";",
"}",
"$",
"this",
"->",
"validate",
"(",
"$",
"itemCreateStruct",
",",
"new",
"ConfigAwareStructConstraint",
"(",
"[",
"'payload'",
"=>",
"$",
"itemCreateStruct",
"->",
"definition",
",",
"]",
")",
")",
";",
"}"
]
| Validates the provided item create struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"item",
"create",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/CollectionValidator.php#L112-L141 | train |
netgen-layouts/layouts-core | lib/Core/Validator/CollectionValidator.php | CollectionValidator.validateItemUpdateStruct | public function validateItemUpdateStruct(Item $item, ItemUpdateStruct $itemUpdateStruct): void
{
$this->validate(
$itemUpdateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $item->getDefinition(),
'allowMissingFields' => true,
]
)
);
} | php | public function validateItemUpdateStruct(Item $item, ItemUpdateStruct $itemUpdateStruct): void
{
$this->validate(
$itemUpdateStruct,
new ConfigAwareStructConstraint(
[
'payload' => $item->getDefinition(),
'allowMissingFields' => true,
]
)
);
} | [
"public",
"function",
"validateItemUpdateStruct",
"(",
"Item",
"$",
"item",
",",
"ItemUpdateStruct",
"$",
"itemUpdateStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"itemUpdateStruct",
",",
"new",
"ConfigAwareStructConstraint",
"(",
"[",
"'payload'",
"=>",
"$",
"item",
"->",
"getDefinition",
"(",
")",
",",
"'allowMissingFields'",
"=>",
"true",
",",
"]",
")",
")",
";",
"}"
]
| Validates the provided item update struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"item",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/CollectionValidator.php#L148-L159 | train |
netgen-layouts/layouts-core | lib/Core/Validator/CollectionValidator.php | CollectionValidator.validateQueryCreateStruct | public function validateQueryCreateStruct(QueryCreateStruct $queryCreateStruct): void
{
$this->validate(
$queryCreateStruct,
[
new ParameterStruct(
[
'parameterDefinitions' => $queryCreateStruct->getQueryType(),
]
),
],
'parameterValues'
);
} | php | public function validateQueryCreateStruct(QueryCreateStruct $queryCreateStruct): void
{
$this->validate(
$queryCreateStruct,
[
new ParameterStruct(
[
'parameterDefinitions' => $queryCreateStruct->getQueryType(),
]
),
],
'parameterValues'
);
} | [
"public",
"function",
"validateQueryCreateStruct",
"(",
"QueryCreateStruct",
"$",
"queryCreateStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"queryCreateStruct",
",",
"[",
"new",
"ParameterStruct",
"(",
"[",
"'parameterDefinitions'",
"=>",
"$",
"queryCreateStruct",
"->",
"getQueryType",
"(",
")",
",",
"]",
")",
",",
"]",
",",
"'parameterValues'",
")",
";",
"}"
]
| Validates the provided query create struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"query",
"create",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/CollectionValidator.php#L166-L179 | train |
netgen-layouts/layouts-core | lib/Core/Validator/CollectionValidator.php | CollectionValidator.validateQueryUpdateStruct | public function validateQueryUpdateStruct(Query $query, QueryUpdateStruct $queryUpdateStruct): void
{
$this->validate(
$queryUpdateStruct,
[
new QueryUpdateStructConstraint(
[
'payload' => $query,
]
),
]
);
} | php | public function validateQueryUpdateStruct(Query $query, QueryUpdateStruct $queryUpdateStruct): void
{
$this->validate(
$queryUpdateStruct,
[
new QueryUpdateStructConstraint(
[
'payload' => $query,
]
),
]
);
} | [
"public",
"function",
"validateQueryUpdateStruct",
"(",
"Query",
"$",
"query",
",",
"QueryUpdateStruct",
"$",
"queryUpdateStruct",
")",
":",
"void",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"queryUpdateStruct",
",",
"[",
"new",
"QueryUpdateStructConstraint",
"(",
"[",
"'payload'",
"=>",
"$",
"query",
",",
"]",
")",
",",
"]",
")",
";",
"}"
]
| Validates the provided query update struct.
@throws \Netgen\BlockManager\Exception\Validation\ValidationException If the validation failed | [
"Validates",
"the",
"provided",
"query",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/Validator/CollectionValidator.php#L186-L198 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Item/ValueTypePass.php | ValueTypePass.buildValueTypes | private function buildValueTypes(ContainerBuilder $container, array $valueTypes): Generator
{
foreach ($valueTypes as $identifier => $valueType) {
$this->validateBrowserType($container, $identifier);
$serviceIdentifier = sprintf('netgen_block_manager.item.value_type.%s', $identifier);
$container->register($serviceIdentifier, ValueType::class)
->setArguments([$identifier, $valueType])
->setLazy(true)
->setPublic(true)
->setFactory([ValueTypeFactory::class, 'buildValueType']);
yield $identifier => new Reference($serviceIdentifier);
}
} | php | private function buildValueTypes(ContainerBuilder $container, array $valueTypes): Generator
{
foreach ($valueTypes as $identifier => $valueType) {
$this->validateBrowserType($container, $identifier);
$serviceIdentifier = sprintf('netgen_block_manager.item.value_type.%s', $identifier);
$container->register($serviceIdentifier, ValueType::class)
->setArguments([$identifier, $valueType])
->setLazy(true)
->setPublic(true)
->setFactory([ValueTypeFactory::class, 'buildValueType']);
yield $identifier => new Reference($serviceIdentifier);
}
} | [
"private",
"function",
"buildValueTypes",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"valueTypes",
")",
":",
"Generator",
"{",
"foreach",
"(",
"$",
"valueTypes",
"as",
"$",
"identifier",
"=>",
"$",
"valueType",
")",
"{",
"$",
"this",
"->",
"validateBrowserType",
"(",
"$",
"container",
",",
"$",
"identifier",
")",
";",
"$",
"serviceIdentifier",
"=",
"sprintf",
"(",
"'netgen_block_manager.item.value_type.%s'",
",",
"$",
"identifier",
")",
";",
"$",
"container",
"->",
"register",
"(",
"$",
"serviceIdentifier",
",",
"ValueType",
"::",
"class",
")",
"->",
"setArguments",
"(",
"[",
"$",
"identifier",
",",
"$",
"valueType",
"]",
")",
"->",
"setLazy",
"(",
"true",
")",
"->",
"setPublic",
"(",
"true",
")",
"->",
"setFactory",
"(",
"[",
"ValueTypeFactory",
"::",
"class",
",",
"'buildValueType'",
"]",
")",
";",
"yield",
"$",
"identifier",
"=>",
"new",
"Reference",
"(",
"$",
"serviceIdentifier",
")",
";",
"}",
"}"
]
| Builds the value type objects from provided configuration. | [
"Builds",
"the",
"value",
"type",
"objects",
"from",
"provided",
"configuration",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Item/ValueTypePass.php#L36-L51 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Item/ValueTypePass.php | ValueTypePass.validateBrowserType | private function validateBrowserType(ContainerBuilder $container, string $valueType): void
{
if ($container->has(sprintf('netgen_content_browser.config.%s', $valueType))) {
return;
}
throw new RuntimeException(
sprintf(
'Netgen Content Browser backend for "%s" value type does not exist.',
$valueType
)
);
} | php | private function validateBrowserType(ContainerBuilder $container, string $valueType): void
{
if ($container->has(sprintf('netgen_content_browser.config.%s', $valueType))) {
return;
}
throw new RuntimeException(
sprintf(
'Netgen Content Browser backend for "%s" value type does not exist.',
$valueType
)
);
} | [
"private",
"function",
"validateBrowserType",
"(",
"ContainerBuilder",
"$",
"container",
",",
"string",
"$",
"valueType",
")",
":",
"void",
"{",
"if",
"(",
"$",
"container",
"->",
"has",
"(",
"sprintf",
"(",
"'netgen_content_browser.config.%s'",
",",
"$",
"valueType",
")",
")",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Netgen Content Browser backend for \"%s\" value type does not exist.'",
",",
"$",
"valueType",
")",
")",
";",
"}"
]
| Validates that the provided Content Browser item type exists in the system. | [
"Validates",
"that",
"the",
"provided",
"Content",
"Browser",
"item",
"type",
"exists",
"in",
"the",
"system",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/DependencyInjection/CompilerPass/Item/ValueTypePass.php#L56-L68 | train |
netgen-layouts/layouts-core | lib/Parameters/ParameterDefinition.php | ParameterDefinition.getOption | public function getOption(string $option)
{
if (!$this->hasOption($option)) {
throw ParameterException::noOption($option);
}
return $this->options[$option];
} | php | public function getOption(string $option)
{
if (!$this->hasOption($option)) {
throw ParameterException::noOption($option);
}
return $this->options[$option];
} | [
"public",
"function",
"getOption",
"(",
"string",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"$",
"option",
")",
")",
"{",
"throw",
"ParameterException",
"::",
"noOption",
"(",
"$",
"option",
")",
";",
"}",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}"
]
| Returns the provided parameter option.
@throws \Netgen\BlockManager\Exception\Parameters\ParameterException If option does not exist
@return mixed | [
"Returns",
"the",
"provided",
"parameter",
"option",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/ParameterDefinition.php#L98-L105 | train |
netgen-layouts/layouts-core | lib/Parameters/ParameterDefinitionCollectionTrait.php | ParameterDefinitionCollectionTrait.getParameterDefinition | public function getParameterDefinition(string $parameterName): ParameterDefinition
{
if (!$this->hasParameterDefinition($parameterName)) {
throw ParameterException::noParameterDefinition($parameterName);
}
return $this->parameterDefinitions[$parameterName];
} | php | public function getParameterDefinition(string $parameterName): ParameterDefinition
{
if (!$this->hasParameterDefinition($parameterName)) {
throw ParameterException::noParameterDefinition($parameterName);
}
return $this->parameterDefinitions[$parameterName];
} | [
"public",
"function",
"getParameterDefinition",
"(",
"string",
"$",
"parameterName",
")",
":",
"ParameterDefinition",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasParameterDefinition",
"(",
"$",
"parameterName",
")",
")",
"{",
"throw",
"ParameterException",
"::",
"noParameterDefinition",
"(",
"$",
"parameterName",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parameterDefinitions",
"[",
"$",
"parameterName",
"]",
";",
"}"
]
| Returns the parameter definition with provided name.
@throws \Netgen\BlockManager\Exception\Parameters\ParameterException If the requested parameter definition does not exist | [
"Returns",
"the",
"parameter",
"definition",
"with",
"provided",
"name",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Parameters/ParameterDefinitionCollectionTrait.php#L31-L38 | train |
netgen-layouts/layouts-core | lib/Utils/DateTimeUtils.php | DateTimeUtils.createFromTimestamp | public static function createFromTimestamp(?int $timestamp = null, ?string $timeZone = null): DateTimeInterface
{
$dateTimeZone = is_string($timeZone) ? new DateTimeZone($timeZone) : null;
$timestamp = is_int($timestamp) ? $timestamp : time();
$dateTime = new DateTimeImmutable('now', $dateTimeZone);
return $dateTime->setTimestamp($timestamp);
} | php | public static function createFromTimestamp(?int $timestamp = null, ?string $timeZone = null): DateTimeInterface
{
$dateTimeZone = is_string($timeZone) ? new DateTimeZone($timeZone) : null;
$timestamp = is_int($timestamp) ? $timestamp : time();
$dateTime = new DateTimeImmutable('now', $dateTimeZone);
return $dateTime->setTimestamp($timestamp);
} | [
"public",
"static",
"function",
"createFromTimestamp",
"(",
"?",
"int",
"$",
"timestamp",
"=",
"null",
",",
"?",
"string",
"$",
"timeZone",
"=",
"null",
")",
":",
"DateTimeInterface",
"{",
"$",
"dateTimeZone",
"=",
"is_string",
"(",
"$",
"timeZone",
")",
"?",
"new",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
":",
"null",
";",
"$",
"timestamp",
"=",
"is_int",
"(",
"$",
"timestamp",
")",
"?",
"$",
"timestamp",
":",
"time",
"(",
")",
";",
"$",
"dateTime",
"=",
"new",
"DateTimeImmutable",
"(",
"'now'",
",",
"$",
"dateTimeZone",
")",
";",
"return",
"$",
"dateTime",
"->",
"setTimestamp",
"(",
"$",
"timestamp",
")",
";",
"}"
]
| Creates a new \DateTimeImmutable instance from provided timestamp and timezone identifiers.
Current timestamp and timezones are used if not provided. | [
"Creates",
"a",
"new",
"\\",
"DateTimeImmutable",
"instance",
"from",
"provided",
"timestamp",
"and",
"timezone",
"identifiers",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Utils/DateTimeUtils.php#L18-L26 | train |
netgen-layouts/layouts-core | lib/Utils/DateTimeUtils.php | DateTimeUtils.createFromArray | public static function createFromArray(array $datetime): ?DateTimeInterface
{
$dateAndTime = $datetime['datetime'] ?? '';
$timeZone = $datetime['timezone'] ?? '';
if ($dateAndTime === '' || !is_string($dateAndTime)) {
return null;
}
if ($timeZone === '' || !is_string($timeZone)) {
return null;
}
return new DateTimeImmutable($dateAndTime, new DateTimeZone($timeZone));
} | php | public static function createFromArray(array $datetime): ?DateTimeInterface
{
$dateAndTime = $datetime['datetime'] ?? '';
$timeZone = $datetime['timezone'] ?? '';
if ($dateAndTime === '' || !is_string($dateAndTime)) {
return null;
}
if ($timeZone === '' || !is_string($timeZone)) {
return null;
}
return new DateTimeImmutable($dateAndTime, new DateTimeZone($timeZone));
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"datetime",
")",
":",
"?",
"DateTimeInterface",
"{",
"$",
"dateAndTime",
"=",
"$",
"datetime",
"[",
"'datetime'",
"]",
"??",
"''",
";",
"$",
"timeZone",
"=",
"$",
"datetime",
"[",
"'timezone'",
"]",
"??",
"''",
";",
"if",
"(",
"$",
"dateAndTime",
"===",
"''",
"||",
"!",
"is_string",
"(",
"$",
"dateAndTime",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"timeZone",
"===",
"''",
"||",
"!",
"is_string",
"(",
"$",
"timeZone",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"DateTimeImmutable",
"(",
"$",
"dateAndTime",
",",
"new",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
")",
";",
"}"
]
| Creates a new \DateTimeImmutable instance from provided array.
The array needs to contain two keys with string values:
1) "datetime" - for date & time in one of the valid formats
2) "timezone" - a valid timezone identifier
Returns null if provided array is not of valid format. | [
"Creates",
"a",
"new",
"\\",
"DateTimeImmutable",
"instance",
"from",
"provided",
"array",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Utils/DateTimeUtils.php#L37-L51 | train |
netgen-layouts/layouts-core | lib/Utils/DateTimeUtils.php | DateTimeUtils.isBetweenDates | public static function isBetweenDates(?DateTimeInterface $date = null, ?DateTimeInterface $from = null, ?DateTimeInterface $to = null): bool
{
$date = $date ?? self::createFromTimestamp();
if ($from instanceof DateTimeInterface && $date < $from) {
return false;
}
if ($to instanceof DateTimeInterface && $date > $to) {
return false;
}
return true;
} | php | public static function isBetweenDates(?DateTimeInterface $date = null, ?DateTimeInterface $from = null, ?DateTimeInterface $to = null): bool
{
$date = $date ?? self::createFromTimestamp();
if ($from instanceof DateTimeInterface && $date < $from) {
return false;
}
if ($to instanceof DateTimeInterface && $date > $to) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"isBetweenDates",
"(",
"?",
"DateTimeInterface",
"$",
"date",
"=",
"null",
",",
"?",
"DateTimeInterface",
"$",
"from",
"=",
"null",
",",
"?",
"DateTimeInterface",
"$",
"to",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"date",
"=",
"$",
"date",
"??",
"self",
"::",
"createFromTimestamp",
"(",
")",
";",
"if",
"(",
"$",
"from",
"instanceof",
"DateTimeInterface",
"&&",
"$",
"date",
"<",
"$",
"from",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"to",
"instanceof",
"DateTimeInterface",
"&&",
"$",
"date",
">",
"$",
"to",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Returns if the provided DateTime instance is between the provided dates. | [
"Returns",
"if",
"the",
"provided",
"DateTime",
"instance",
"is",
"between",
"the",
"provided",
"dates",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Utils/DateTimeUtils.php#L56-L69 | train |
netgen-layouts/layouts-core | lib/Utils/DateTimeUtils.php | DateTimeUtils.parseTimeZone | private static function parseTimeZone(string $timeZone): array
{
$parts = explode('/', $timeZone);
if (count($parts) > 2) {
return [$parts[0], $parts[1] . ' / ' . $parts[2]];
}
if (count($parts) > 1) {
return [$parts[0], $parts[1]];
}
return ['Other', $parts[0]];
} | php | private static function parseTimeZone(string $timeZone): array
{
$parts = explode('/', $timeZone);
if (count($parts) > 2) {
return [$parts[0], $parts[1] . ' / ' . $parts[2]];
}
if (count($parts) > 1) {
return [$parts[0], $parts[1]];
}
return ['Other', $parts[0]];
} | [
"private",
"static",
"function",
"parseTimeZone",
"(",
"string",
"$",
"timeZone",
")",
":",
"array",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"timeZone",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"2",
")",
"{",
"return",
"[",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
".",
"' / '",
".",
"$",
"parts",
"[",
"2",
"]",
"]",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"return",
"[",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
"]",
";",
"}",
"return",
"[",
"'Other'",
",",
"$",
"parts",
"[",
"0",
"]",
"]",
";",
"}"
]
| Returns the array with human readable region and timezone name for the provided
timezone identifier. | [
"Returns",
"the",
"array",
"with",
"human",
"readable",
"region",
"and",
"timezone",
"name",
"for",
"the",
"provided",
"timezone",
"identifier",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Utils/DateTimeUtils.php#L93-L106 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php | GlobalVariable.getLayoutView | public function getLayoutView()
{
$currentRequest = $this->requestStack->getCurrentRequest();
$masterRequest = $this->requestStack->getMasterRequest();
if (!$currentRequest instanceof Request || !$masterRequest instanceof Request) {
return null;
}
if ($masterRequest->attributes->has('ngbmExceptionLayoutView')) {
if ($currentRequest !== $masterRequest || !$masterRequest->attributes->has('ngbmLayoutView')) {
return $masterRequest->attributes->get('ngbmExceptionLayoutView');
}
}
return $masterRequest->attributes->get('ngbmLayoutView');
} | php | public function getLayoutView()
{
$currentRequest = $this->requestStack->getCurrentRequest();
$masterRequest = $this->requestStack->getMasterRequest();
if (!$currentRequest instanceof Request || !$masterRequest instanceof Request) {
return null;
}
if ($masterRequest->attributes->has('ngbmExceptionLayoutView')) {
if ($currentRequest !== $masterRequest || !$masterRequest->attributes->has('ngbmLayoutView')) {
return $masterRequest->attributes->get('ngbmExceptionLayoutView');
}
}
return $masterRequest->attributes->get('ngbmLayoutView');
} | [
"public",
"function",
"getLayoutView",
"(",
")",
"{",
"$",
"currentRequest",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"$",
"masterRequest",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getMasterRequest",
"(",
")",
";",
"if",
"(",
"!",
"$",
"currentRequest",
"instanceof",
"Request",
"||",
"!",
"$",
"masterRequest",
"instanceof",
"Request",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"masterRequest",
"->",
"attributes",
"->",
"has",
"(",
"'ngbmExceptionLayoutView'",
")",
")",
"{",
"if",
"(",
"$",
"currentRequest",
"!==",
"$",
"masterRequest",
"||",
"!",
"$",
"masterRequest",
"->",
"attributes",
"->",
"has",
"(",
"'ngbmLayoutView'",
")",
")",
"{",
"return",
"$",
"masterRequest",
"->",
"attributes",
"->",
"get",
"(",
"'ngbmExceptionLayoutView'",
")",
";",
"}",
"}",
"return",
"$",
"masterRequest",
"->",
"attributes",
"->",
"get",
"(",
"'ngbmLayoutView'",
")",
";",
"}"
]
| Returns the currently resolved layout view.
Since the regular Symfony exceptions are rendered only in sub-requests,
we can return the resolved non-error layout for master requests even if the
exception layout is resolved too (that might happen if an error or exception
happened inside a user implemented sub-request, like rendering a block
item).
In other words, we return the resolved exception layout only in case of a
sub-request (this case happens if an error/exception happens during the
rendering of the page) or in case of a master request if non-error layout
is NOT resolved (this case happens if an error/exception happens before
the rendering of the page).
All other cases receive the non-error layout if it exists.
@return \Netgen\BlockManager\View\View\LayoutViewInterface|false|null | [
"Returns",
"the",
"currently",
"resolved",
"layout",
"view",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php#L113-L129 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php | GlobalVariable.getLayout | public function getLayout(): ?Layout
{
$layoutView = $this->getLayoutView();
if (!$layoutView instanceof LayoutViewInterface) {
return null;
}
return $layoutView->getLayout();
} | php | public function getLayout(): ?Layout
{
$layoutView = $this->getLayoutView();
if (!$layoutView instanceof LayoutViewInterface) {
return null;
}
return $layoutView->getLayout();
} | [
"public",
"function",
"getLayout",
"(",
")",
":",
"?",
"Layout",
"{",
"$",
"layoutView",
"=",
"$",
"this",
"->",
"getLayoutView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"layoutView",
"instanceof",
"LayoutViewInterface",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"layoutView",
"->",
"getLayout",
"(",
")",
";",
"}"
]
| Returns the currently resolved layout or null if no layout was resolved. | [
"Returns",
"the",
"currently",
"resolved",
"layout",
"or",
"null",
"if",
"no",
"layout",
"was",
"resolved",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php#L134-L142 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php | GlobalVariable.getRule | public function getRule(): ?Rule
{
$layoutView = $this->getLayoutView();
if (!$layoutView instanceof LayoutViewInterface) {
return null;
}
return $layoutView->getParameter('rule');
} | php | public function getRule(): ?Rule
{
$layoutView = $this->getLayoutView();
if (!$layoutView instanceof LayoutViewInterface) {
return null;
}
return $layoutView->getParameter('rule');
} | [
"public",
"function",
"getRule",
"(",
")",
":",
"?",
"Rule",
"{",
"$",
"layoutView",
"=",
"$",
"this",
"->",
"getLayoutView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"layoutView",
"instanceof",
"LayoutViewInterface",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"layoutView",
"->",
"getParameter",
"(",
"'rule'",
")",
";",
"}"
]
| Returns the rule used to resolve the current layout or null if no layout was resolved. | [
"Returns",
"the",
"rule",
"used",
"to",
"resolve",
"the",
"current",
"layout",
"or",
"null",
"if",
"no",
"layout",
"was",
"resolved",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php#L147-L155 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php | GlobalVariable.getPageLayoutTemplate | public function getPageLayoutTemplate(): string
{
$this->pageLayoutTemplate = $this->pageLayoutTemplate ?? $this->pageLayoutResolver->resolvePageLayout();
return $this->pageLayoutTemplate;
} | php | public function getPageLayoutTemplate(): string
{
$this->pageLayoutTemplate = $this->pageLayoutTemplate ?? $this->pageLayoutResolver->resolvePageLayout();
return $this->pageLayoutTemplate;
} | [
"public",
"function",
"getPageLayoutTemplate",
"(",
")",
":",
"string",
"{",
"$",
"this",
"->",
"pageLayoutTemplate",
"=",
"$",
"this",
"->",
"pageLayoutTemplate",
"??",
"$",
"this",
"->",
"pageLayoutResolver",
"->",
"resolvePageLayout",
"(",
")",
";",
"return",
"$",
"this",
"->",
"pageLayoutTemplate",
";",
"}"
]
| Returns the pagelayout template. | [
"Returns",
"the",
"pagelayout",
"template",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php#L168-L173 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php | GlobalVariable.getLayoutTemplate | public function getLayoutTemplate(string $context = ViewInterface::CONTEXT_DEFAULT): ?string
{
$layoutView = $this->buildLayoutView($context);
if (!$layoutView instanceof LayoutViewInterface) {
return $this->getPageLayoutTemplate();
}
return $layoutView->getTemplate();
} | php | public function getLayoutTemplate(string $context = ViewInterface::CONTEXT_DEFAULT): ?string
{
$layoutView = $this->buildLayoutView($context);
if (!$layoutView instanceof LayoutViewInterface) {
return $this->getPageLayoutTemplate();
}
return $layoutView->getTemplate();
} | [
"public",
"function",
"getLayoutTemplate",
"(",
"string",
"$",
"context",
"=",
"ViewInterface",
"::",
"CONTEXT_DEFAULT",
")",
":",
"?",
"string",
"{",
"$",
"layoutView",
"=",
"$",
"this",
"->",
"buildLayoutView",
"(",
"$",
"context",
")",
";",
"if",
"(",
"!",
"$",
"layoutView",
"instanceof",
"LayoutViewInterface",
")",
"{",
"return",
"$",
"this",
"->",
"getPageLayoutTemplate",
"(",
")",
";",
"}",
"return",
"$",
"layoutView",
"->",
"getTemplate",
"(",
")",
";",
"}"
]
| Returns the currently valid layout template, or base pagelayout if
no layout was resolved. | [
"Returns",
"the",
"currently",
"valid",
"layout",
"template",
"or",
"base",
"pagelayout",
"if",
"no",
"layout",
"was",
"resolved",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php#L179-L187 | train |
netgen-layouts/layouts-core | bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php | GlobalVariable.buildLayoutView | private function buildLayoutView(string $context = ViewInterface::CONTEXT_DEFAULT)
{
$currentRequest = $this->requestStack->getCurrentRequest();
$masterRequest = $this->requestStack->getMasterRequest();
if (!$currentRequest instanceof Request || !$masterRequest instanceof Request) {
return null;
}
if ($masterRequest->attributes->has('ngbmExceptionLayoutView')) {
// After an exception layout is resolved, this case either means that
// the main layout does not exist at all (because the error
// happened before the rendering) or that it is already resolved
// (if the error happened in subrequest), so this is a subsequent
// call where we can safely return null in all cases.
return null;
}
if (
!$currentRequest->attributes->has('exception') &&
$masterRequest->attributes->has('ngbmLayoutView')
) {
// This is the case where we request the main layout more than once
// within the regular page display, without the exception, so again
// we return null.
return null;
}
// Once we're here, we either request the main layout when there's no
// exception, or the exception layout (both of those for the first time).
$layoutView = false;
$resolvedRule = $this->layoutResolver->resolveRule();
if ($resolvedRule instanceof Rule) {
$layoutView = $this->viewBuilder->buildView(
$resolvedRule->getLayout(),
$context,
[
'rule' => $resolvedRule,
]
);
}
$masterRequest->attributes->set(
$currentRequest->attributes->has('exception') ?
'ngbmExceptionLayoutView' :
'ngbmLayoutView',
$layoutView
);
return $layoutView;
} | php | private function buildLayoutView(string $context = ViewInterface::CONTEXT_DEFAULT)
{
$currentRequest = $this->requestStack->getCurrentRequest();
$masterRequest = $this->requestStack->getMasterRequest();
if (!$currentRequest instanceof Request || !$masterRequest instanceof Request) {
return null;
}
if ($masterRequest->attributes->has('ngbmExceptionLayoutView')) {
// After an exception layout is resolved, this case either means that
// the main layout does not exist at all (because the error
// happened before the rendering) or that it is already resolved
// (if the error happened in subrequest), so this is a subsequent
// call where we can safely return null in all cases.
return null;
}
if (
!$currentRequest->attributes->has('exception') &&
$masterRequest->attributes->has('ngbmLayoutView')
) {
// This is the case where we request the main layout more than once
// within the regular page display, without the exception, so again
// we return null.
return null;
}
// Once we're here, we either request the main layout when there's no
// exception, or the exception layout (both of those for the first time).
$layoutView = false;
$resolvedRule = $this->layoutResolver->resolveRule();
if ($resolvedRule instanceof Rule) {
$layoutView = $this->viewBuilder->buildView(
$resolvedRule->getLayout(),
$context,
[
'rule' => $resolvedRule,
]
);
}
$masterRequest->attributes->set(
$currentRequest->attributes->has('exception') ?
'ngbmExceptionLayoutView' :
'ngbmLayoutView',
$layoutView
);
return $layoutView;
} | [
"private",
"function",
"buildLayoutView",
"(",
"string",
"$",
"context",
"=",
"ViewInterface",
"::",
"CONTEXT_DEFAULT",
")",
"{",
"$",
"currentRequest",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"$",
"masterRequest",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getMasterRequest",
"(",
")",
";",
"if",
"(",
"!",
"$",
"currentRequest",
"instanceof",
"Request",
"||",
"!",
"$",
"masterRequest",
"instanceof",
"Request",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"masterRequest",
"->",
"attributes",
"->",
"has",
"(",
"'ngbmExceptionLayoutView'",
")",
")",
"{",
"// After an exception layout is resolved, this case either means that",
"// the main layout does not exist at all (because the error",
"// happened before the rendering) or that it is already resolved",
"// (if the error happened in subrequest), so this is a subsequent",
"// call where we can safely return null in all cases.",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"currentRequest",
"->",
"attributes",
"->",
"has",
"(",
"'exception'",
")",
"&&",
"$",
"masterRequest",
"->",
"attributes",
"->",
"has",
"(",
"'ngbmLayoutView'",
")",
")",
"{",
"// This is the case where we request the main layout more than once",
"// within the regular page display, without the exception, so again",
"// we return null.",
"return",
"null",
";",
"}",
"// Once we're here, we either request the main layout when there's no",
"// exception, or the exception layout (both of those for the first time).",
"$",
"layoutView",
"=",
"false",
";",
"$",
"resolvedRule",
"=",
"$",
"this",
"->",
"layoutResolver",
"->",
"resolveRule",
"(",
")",
";",
"if",
"(",
"$",
"resolvedRule",
"instanceof",
"Rule",
")",
"{",
"$",
"layoutView",
"=",
"$",
"this",
"->",
"viewBuilder",
"->",
"buildView",
"(",
"$",
"resolvedRule",
"->",
"getLayout",
"(",
")",
",",
"$",
"context",
",",
"[",
"'rule'",
"=>",
"$",
"resolvedRule",
",",
"]",
")",
";",
"}",
"$",
"masterRequest",
"->",
"attributes",
"->",
"set",
"(",
"$",
"currentRequest",
"->",
"attributes",
"->",
"has",
"(",
"'exception'",
")",
"?",
"'ngbmExceptionLayoutView'",
":",
"'ngbmLayoutView'",
",",
"$",
"layoutView",
")",
";",
"return",
"$",
"layoutView",
";",
"}"
]
| Resolves the used layout, based on current conditions.
Only resolves and returns the layout view once per request for regular page,
and once if an exception happens. Subsequent calls will simply return null.
See class docs for more details.
@return \Netgen\BlockManager\View\ViewInterface|false|null | [
"Resolves",
"the",
"used",
"layout",
"based",
"on",
"current",
"conditions",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/bundles/BlockManagerBundle/Templating/Twig/GlobalVariable.php#L207-L259 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/LayoutStructBuilder.php | LayoutStructBuilder.newLayoutCreateStruct | public function newLayoutCreateStruct(LayoutTypeInterface $layoutType, string $name, string $mainLocale): LayoutCreateStruct
{
$struct = new LayoutCreateStruct();
$struct->layoutType = $layoutType;
$struct->name = $name;
$struct->mainLocale = $mainLocale;
return $struct;
} | php | public function newLayoutCreateStruct(LayoutTypeInterface $layoutType, string $name, string $mainLocale): LayoutCreateStruct
{
$struct = new LayoutCreateStruct();
$struct->layoutType = $layoutType;
$struct->name = $name;
$struct->mainLocale = $mainLocale;
return $struct;
} | [
"public",
"function",
"newLayoutCreateStruct",
"(",
"LayoutTypeInterface",
"$",
"layoutType",
",",
"string",
"$",
"name",
",",
"string",
"$",
"mainLocale",
")",
":",
"LayoutCreateStruct",
"{",
"$",
"struct",
"=",
"new",
"LayoutCreateStruct",
"(",
")",
";",
"$",
"struct",
"->",
"layoutType",
"=",
"$",
"layoutType",
";",
"$",
"struct",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"struct",
"->",
"mainLocale",
"=",
"$",
"mainLocale",
";",
"return",
"$",
"struct",
";",
"}"
]
| Creates a new layout create struct from the provided values. | [
"Creates",
"a",
"new",
"layout",
"create",
"struct",
"from",
"the",
"provided",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/LayoutStructBuilder.php#L18-L26 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/LayoutStructBuilder.php | LayoutStructBuilder.newLayoutUpdateStruct | public function newLayoutUpdateStruct(?Layout $layout = null): LayoutUpdateStruct
{
$layoutUpdateStruct = new LayoutUpdateStruct();
if (!$layout instanceof Layout) {
return $layoutUpdateStruct;
}
$layoutUpdateStruct->name = $layout->getName();
$layoutUpdateStruct->description = $layout->getDescription();
return $layoutUpdateStruct;
} | php | public function newLayoutUpdateStruct(?Layout $layout = null): LayoutUpdateStruct
{
$layoutUpdateStruct = new LayoutUpdateStruct();
if (!$layout instanceof Layout) {
return $layoutUpdateStruct;
}
$layoutUpdateStruct->name = $layout->getName();
$layoutUpdateStruct->description = $layout->getDescription();
return $layoutUpdateStruct;
} | [
"public",
"function",
"newLayoutUpdateStruct",
"(",
"?",
"Layout",
"$",
"layout",
"=",
"null",
")",
":",
"LayoutUpdateStruct",
"{",
"$",
"layoutUpdateStruct",
"=",
"new",
"LayoutUpdateStruct",
"(",
")",
";",
"if",
"(",
"!",
"$",
"layout",
"instanceof",
"Layout",
")",
"{",
"return",
"$",
"layoutUpdateStruct",
";",
"}",
"$",
"layoutUpdateStruct",
"->",
"name",
"=",
"$",
"layout",
"->",
"getName",
"(",
")",
";",
"$",
"layoutUpdateStruct",
"->",
"description",
"=",
"$",
"layout",
"->",
"getDescription",
"(",
")",
";",
"return",
"$",
"layoutUpdateStruct",
";",
"}"
]
| Creates a new layout update struct.
If the layout is provided, initial data is copied from the layout. | [
"Creates",
"a",
"new",
"layout",
"update",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/LayoutStructBuilder.php#L33-L45 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/LayoutStructBuilder.php | LayoutStructBuilder.newLayoutCopyStruct | public function newLayoutCopyStruct(?Layout $layout = null): LayoutCopyStruct
{
$layoutCopyStruct = new LayoutCopyStruct();
if (!$layout instanceof Layout) {
return $layoutCopyStruct;
}
$layoutCopyStruct->name = $layout->getName() . ' (copy)';
return $layoutCopyStruct;
} | php | public function newLayoutCopyStruct(?Layout $layout = null): LayoutCopyStruct
{
$layoutCopyStruct = new LayoutCopyStruct();
if (!$layout instanceof Layout) {
return $layoutCopyStruct;
}
$layoutCopyStruct->name = $layout->getName() . ' (copy)';
return $layoutCopyStruct;
} | [
"public",
"function",
"newLayoutCopyStruct",
"(",
"?",
"Layout",
"$",
"layout",
"=",
"null",
")",
":",
"LayoutCopyStruct",
"{",
"$",
"layoutCopyStruct",
"=",
"new",
"LayoutCopyStruct",
"(",
")",
";",
"if",
"(",
"!",
"$",
"layout",
"instanceof",
"Layout",
")",
"{",
"return",
"$",
"layoutCopyStruct",
";",
"}",
"$",
"layoutCopyStruct",
"->",
"name",
"=",
"$",
"layout",
"->",
"getName",
"(",
")",
".",
"' (copy)'",
";",
"return",
"$",
"layoutCopyStruct",
";",
"}"
]
| Creates a new layout copy struct.
If the layout is provided, initial data is copied from the layout. | [
"Creates",
"a",
"new",
"layout",
"copy",
"struct",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/LayoutStructBuilder.php#L52-L63 | train |
netgen-layouts/layouts-core | lib/Core/StructBuilder/LayoutResolverStructBuilder.php | LayoutResolverStructBuilder.newTargetCreateStruct | public function newTargetCreateStruct(string $type): TargetCreateStruct
{
$struct = new TargetCreateStruct();
$struct->type = $type;
return $struct;
} | php | public function newTargetCreateStruct(string $type): TargetCreateStruct
{
$struct = new TargetCreateStruct();
$struct->type = $type;
return $struct;
} | [
"public",
"function",
"newTargetCreateStruct",
"(",
"string",
"$",
"type",
")",
":",
"TargetCreateStruct",
"{",
"$",
"struct",
"=",
"new",
"TargetCreateStruct",
"(",
")",
";",
"$",
"struct",
"->",
"type",
"=",
"$",
"type",
";",
"return",
"$",
"struct",
";",
"}"
]
| Creates a new target create struct from the provided values. | [
"Creates",
"a",
"new",
"target",
"create",
"struct",
"from",
"the",
"provided",
"values",
"."
]
| 81b4dd0d3043b926286f9a4890e1d8deebb103e9 | https://github.com/netgen-layouts/layouts-core/blob/81b4dd0d3043b926286f9a4890e1d8deebb103e9/lib/Core/StructBuilder/LayoutResolverStructBuilder.php#L44-L50 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.