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 |
---|---|---|---|---|---|---|---|---|---|---|---|
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.collectionIdentFallback | public function collectionIdentFallback()
{
$metadata = $this->proto()->metadata();
if (isset($metadata['admin']['default_list'])) {
return $metadata['admin']['default_list'];
}
return $this->collectionIdent;
} | php | public function collectionIdentFallback()
{
$metadata = $this->proto()->metadata();
if (isset($metadata['admin']['default_list'])) {
return $metadata['admin']['default_list'];
}
return $this->collectionIdent;
} | [
"public",
"function",
"collectionIdentFallback",
"(",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"proto",
"(",
")",
"->",
"metadata",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
"[",
"'default_list'",
"]",
")",
")",
"{",
"return",
"$",
"metadata",
"[",
"'admin'",
"]",
"[",
"'default_list'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"collectionIdent",
";",
"}"
]
| Retrieve a key for the collection structure to use.
If the collection key is undefined, resolve a fallback.
@return string | [
"Retrieve",
"a",
"key",
"for",
"the",
"collection",
"structure",
"to",
"use",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L308-L317 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.collectionMetadata | public function collectionMetadata()
{
$proto = $this->proto();
$collectionIdent = $this->collectionIdent();
if (!$collectionIdent) {
$collectionIdent = $this->collectionIdentFallback();
}
if ($collectionIdent && $proto->view()) {
$collectionIdent = $proto->render($collectionIdent);
}
if (!$collectionIdent) {
return [];
}
$objMeta = $proto->metadata();
if (isset($objMeta['admin']['lists'][$collectionIdent])) {
return $objMeta['admin']['lists'][$collectionIdent];
} else {
return [];
}
} | php | public function collectionMetadata()
{
$proto = $this->proto();
$collectionIdent = $this->collectionIdent();
if (!$collectionIdent) {
$collectionIdent = $this->collectionIdentFallback();
}
if ($collectionIdent && $proto->view()) {
$collectionIdent = $proto->render($collectionIdent);
}
if (!$collectionIdent) {
return [];
}
$objMeta = $proto->metadata();
if (isset($objMeta['admin']['lists'][$collectionIdent])) {
return $objMeta['admin']['lists'][$collectionIdent];
} else {
return [];
}
} | [
"public",
"function",
"collectionMetadata",
"(",
")",
"{",
"$",
"proto",
"=",
"$",
"this",
"->",
"proto",
"(",
")",
";",
"$",
"collectionIdent",
"=",
"$",
"this",
"->",
"collectionIdent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collectionIdent",
")",
"{",
"$",
"collectionIdent",
"=",
"$",
"this",
"->",
"collectionIdentFallback",
"(",
")",
";",
"}",
"if",
"(",
"$",
"collectionIdent",
"&&",
"$",
"proto",
"->",
"view",
"(",
")",
")",
"{",
"$",
"collectionIdent",
"=",
"$",
"proto",
"->",
"render",
"(",
"$",
"collectionIdent",
")",
";",
"}",
"if",
"(",
"!",
"$",
"collectionIdent",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"objMeta",
"=",
"$",
"proto",
"->",
"metadata",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"objMeta",
"[",
"'admin'",
"]",
"[",
"'lists'",
"]",
"[",
"$",
"collectionIdent",
"]",
")",
")",
"{",
"return",
"$",
"objMeta",
"[",
"'admin'",
"]",
"[",
"'lists'",
"]",
"[",
"$",
"collectionIdent",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}"
]
| Return the current collection metadata.
@return array | [
"Return",
"the",
"current",
"collection",
"metadata",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L334-L358 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.collectionConfig | public function collectionConfig()
{
if ($this->collectionConfig === null) {
$this->collectionConfig = $this->createCollectionConfig();
}
return $this->collectionConfig;
} | php | public function collectionConfig()
{
if ($this->collectionConfig === null) {
$this->collectionConfig = $this->createCollectionConfig();
}
return $this->collectionConfig;
} | [
"public",
"function",
"collectionConfig",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collectionConfig",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"collectionConfig",
"=",
"$",
"this",
"->",
"createCollectionConfig",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"collectionConfig",
";",
"}"
]
| Retrieve the collection configset.
@return array|null | [
"Retrieve",
"the",
"collection",
"configset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L365-L372 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.setCollectionConfig | public function setCollectionConfig($config)
{
if (empty($config) || !is_array($config)) {
$config = [];
}
$this->collectionConfig = array_replace_recursive(
$this->defaultCollectionConfig(),
$this->parseCollectionConfig($config)
);
return $this;
} | php | public function setCollectionConfig($config)
{
if (empty($config) || !is_array($config)) {
$config = [];
}
$this->collectionConfig = array_replace_recursive(
$this->defaultCollectionConfig(),
$this->parseCollectionConfig($config)
);
return $this;
} | [
"public",
"function",
"setCollectionConfig",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"config",
")",
"||",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"collectionConfig",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"defaultCollectionConfig",
"(",
")",
",",
"$",
"this",
"->",
"parseCollectionConfig",
"(",
"$",
"config",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Replace the collection's configset with the given parameters.
@param mixed $config New collection config values.
@return CollectionContainerInterface Chainable | [
"Replace",
"the",
"collection",
"s",
"configset",
"with",
"the",
"given",
"parameters",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L380-L392 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.mergeCollectionConfig | public function mergeCollectionConfig(array $config)
{
if ($this->collectionConfig === null) {
$this->setCollectionConfig($config);
return $this;
}
$this->collectionConfig = array_replace_recursive(
$this->defaultCollectionConfig(),
$this->collectionConfig,
$this->parseCollectionConfig($config)
);
return $this;
} | php | public function mergeCollectionConfig(array $config)
{
if ($this->collectionConfig === null) {
$this->setCollectionConfig($config);
return $this;
}
$this->collectionConfig = array_replace_recursive(
$this->defaultCollectionConfig(),
$this->collectionConfig,
$this->parseCollectionConfig($config)
);
return $this;
} | [
"public",
"function",
"mergeCollectionConfig",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collectionConfig",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setCollectionConfig",
"(",
"$",
"config",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"collectionConfig",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"defaultCollectionConfig",
"(",
")",
",",
"$",
"this",
"->",
"collectionConfig",
",",
"$",
"this",
"->",
"parseCollectionConfig",
"(",
"$",
"config",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Merge given parameters into the collection's configset.
@param array $config New collection config values.
@return self | [
"Merge",
"given",
"parameters",
"into",
"the",
"collection",
"s",
"configset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L400-L415 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.defaultCollectionConfig | protected function defaultCollectionConfig()
{
if ($this->defaultCollectionConfig === null) {
$this->defaultCollectionConfig = $this->collectionMetadata();
}
return $this->defaultCollectionConfig;
} | php | protected function defaultCollectionConfig()
{
if ($this->defaultCollectionConfig === null) {
$this->defaultCollectionConfig = $this->collectionMetadata();
}
return $this->defaultCollectionConfig;
} | [
"protected",
"function",
"defaultCollectionConfig",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"defaultCollectionConfig",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultCollectionConfig",
"=",
"$",
"this",
"->",
"collectionMetadata",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"defaultCollectionConfig",
";",
"}"
]
| Retrieve the default collection configuration.
The default configset is determined by the collection ident and object type, if assigned.
@return array|null | [
"Retrieve",
"the",
"default",
"collection",
"configuration",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L437-L444 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.objectRows | public function objectRows()
{
// Get properties as defined in object's list metadata
$properties = $this->sortProperties();
$propOptions = $this->propertiesOptions();
// Collection objects
$objects = $this->sortObjects();
// Go through each object to generate an array of properties listed in object's list metadata
foreach ($objects as $object) {
if (isset($object['requiredAclPermissions']) && !empty($object['requiredAclPermissions'])) {
if ($this->hasPermissions($object['requiredAclPermissions']) === false) {
continue;
}
}
$objectProperties = [];
foreach ($properties as $propertyIdent => $propertyData) {
$property = $object->property($propertyIdent);
if (isset($propOptions[$propertyIdent]) && is_array($propOptions[$propertyIdent])) {
$property->setData($propOptions[$propertyIdent]);
}
$this->setupDisplayPropertyValue($object, $property);
$displayType = $this->display->displayType();
$this->display->setPropertyVal($object->propertyValue($propertyIdent));
$propertyValue = $this->view()->renderTemplate($displayType, $this->display);
$cell = $this->parsePropertyCell($object, $property, $propertyValue);
$objectProperties[] = $cell;
};
$this->currentObj = $object;
$this->currentObjId = $object->id();
$row = $this->parseObjectRow($object, $objectProperties);
yield $row;
}
$this->currentObj = null;
$this->currentObjId = null;
} | php | public function objectRows()
{
// Get properties as defined in object's list metadata
$properties = $this->sortProperties();
$propOptions = $this->propertiesOptions();
// Collection objects
$objects = $this->sortObjects();
// Go through each object to generate an array of properties listed in object's list metadata
foreach ($objects as $object) {
if (isset($object['requiredAclPermissions']) && !empty($object['requiredAclPermissions'])) {
if ($this->hasPermissions($object['requiredAclPermissions']) === false) {
continue;
}
}
$objectProperties = [];
foreach ($properties as $propertyIdent => $propertyData) {
$property = $object->property($propertyIdent);
if (isset($propOptions[$propertyIdent]) && is_array($propOptions[$propertyIdent])) {
$property->setData($propOptions[$propertyIdent]);
}
$this->setupDisplayPropertyValue($object, $property);
$displayType = $this->display->displayType();
$this->display->setPropertyVal($object->propertyValue($propertyIdent));
$propertyValue = $this->view()->renderTemplate($displayType, $this->display);
$cell = $this->parsePropertyCell($object, $property, $propertyValue);
$objectProperties[] = $cell;
};
$this->currentObj = $object;
$this->currentObjId = $object->id();
$row = $this->parseObjectRow($object, $objectProperties);
yield $row;
}
$this->currentObj = null;
$this->currentObjId = null;
} | [
"public",
"function",
"objectRows",
"(",
")",
"{",
"// Get properties as defined in object's list metadata",
"$",
"properties",
"=",
"$",
"this",
"->",
"sortProperties",
"(",
")",
";",
"$",
"propOptions",
"=",
"$",
"this",
"->",
"propertiesOptions",
"(",
")",
";",
"// Collection objects",
"$",
"objects",
"=",
"$",
"this",
"->",
"sortObjects",
"(",
")",
";",
"// Go through each object to generate an array of properties listed in object's list metadata",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"[",
"'requiredAclPermissions'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"object",
"[",
"'requiredAclPermissions'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasPermissions",
"(",
"$",
"object",
"[",
"'requiredAclPermissions'",
"]",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"objectProperties",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"propertyIdent",
"=>",
"$",
"propertyData",
")",
"{",
"$",
"property",
"=",
"$",
"object",
"->",
"property",
"(",
"$",
"propertyIdent",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"propOptions",
"[",
"$",
"propertyIdent",
"]",
")",
"&&",
"is_array",
"(",
"$",
"propOptions",
"[",
"$",
"propertyIdent",
"]",
")",
")",
"{",
"$",
"property",
"->",
"setData",
"(",
"$",
"propOptions",
"[",
"$",
"propertyIdent",
"]",
")",
";",
"}",
"$",
"this",
"->",
"setupDisplayPropertyValue",
"(",
"$",
"object",
",",
"$",
"property",
")",
";",
"$",
"displayType",
"=",
"$",
"this",
"->",
"display",
"->",
"displayType",
"(",
")",
";",
"$",
"this",
"->",
"display",
"->",
"setPropertyVal",
"(",
"$",
"object",
"->",
"propertyValue",
"(",
"$",
"propertyIdent",
")",
")",
";",
"$",
"propertyValue",
"=",
"$",
"this",
"->",
"view",
"(",
")",
"->",
"renderTemplate",
"(",
"$",
"displayType",
",",
"$",
"this",
"->",
"display",
")",
";",
"$",
"cell",
"=",
"$",
"this",
"->",
"parsePropertyCell",
"(",
"$",
"object",
",",
"$",
"property",
",",
"$",
"propertyValue",
")",
";",
"$",
"objectProperties",
"[",
"]",
"=",
"$",
"cell",
";",
"}",
";",
"$",
"this",
"->",
"currentObj",
"=",
"$",
"object",
";",
"$",
"this",
"->",
"currentObjId",
"=",
"$",
"object",
"->",
"id",
"(",
")",
";",
"$",
"row",
"=",
"$",
"this",
"->",
"parseObjectRow",
"(",
"$",
"object",
",",
"$",
"objectProperties",
")",
";",
"yield",
"$",
"row",
";",
"}",
"$",
"this",
"->",
"currentObj",
"=",
"null",
";",
"$",
"this",
"->",
"currentObjId",
"=",
"null",
";",
"}"
]
| Supplies properties for objects in table template specific to object configuration.
@return array This metod is a generator. | [
"Supplies",
"properties",
"for",
"objects",
"in",
"table",
"template",
"specific",
"to",
"object",
"configuration",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L692-L738 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/CollectionContainerTrait.php | CollectionContainerTrait.objLabels | public function objLabels()
{
if ($this->objLabels === null) {
$objLabels = [];
$proto = $this->proto();
$objMetadata = $proto->metadata();
if (isset($objMetadata['labels']) && !empty($objMetadata['labels'])) {
$objLabels = $objMetadata['labels'];
array_walk($objLabels, function(&$value) {
$value = $this->translator()->translation($value);
});
$this->objLabels = $objLabels;
}
}
return $this->objLabels;
} | php | public function objLabels()
{
if ($this->objLabels === null) {
$objLabels = [];
$proto = $this->proto();
$objMetadata = $proto->metadata();
if (isset($objMetadata['labels']) && !empty($objMetadata['labels'])) {
$objLabels = $objMetadata['labels'];
array_walk($objLabels, function(&$value) {
$value = $this->translator()->translation($value);
});
$this->objLabels = $objLabels;
}
}
return $this->objLabels;
} | [
"public",
"function",
"objLabels",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"objLabels",
"===",
"null",
")",
"{",
"$",
"objLabels",
"=",
"[",
"]",
";",
"$",
"proto",
"=",
"$",
"this",
"->",
"proto",
"(",
")",
";",
"$",
"objMetadata",
"=",
"$",
"proto",
"->",
"metadata",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"objMetadata",
"[",
"'labels'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"objMetadata",
"[",
"'labels'",
"]",
")",
")",
"{",
"$",
"objLabels",
"=",
"$",
"objMetadata",
"[",
"'labels'",
"]",
";",
"array_walk",
"(",
"$",
"objLabels",
",",
"function",
"(",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"value",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"objLabels",
"=",
"$",
"objLabels",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"objLabels",
";",
"}"
]
| Retrieve the object's labels.
@return array|null | [
"Retrieve",
"the",
"object",
"s",
"labels",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L874-L890 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/JsonEditorInput.php | JsonEditorInput.editorOptions | public function editorOptions()
{
if ($this->editorOptions === null) {
$this->editorOptions = $this->defaultEditorOptions();
}
return $this->editorOptions;
} | php | public function editorOptions()
{
if ($this->editorOptions === null) {
$this->editorOptions = $this->defaultEditorOptions();
}
return $this->editorOptions;
} | [
"public",
"function",
"editorOptions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"editorOptions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"editorOptions",
"=",
"$",
"this",
"->",
"defaultEditorOptions",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"editorOptions",
";",
"}"
]
| Retrieve the editor's options.
@return array | [
"Retrieve",
"the",
"editor",
"s",
"options",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/JsonEditorInput.php#L82-L89 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/JsonEditorInput.php | JsonEditorInput.jsonVal | public function jsonVal()
{
$json = $this->propertyVal();
if (!is_string($json)) {
$json = json_encode($json);
}
if (!$json || $json == 'null') {
$json = '';
}
return $json;
} | php | public function jsonVal()
{
$json = $this->propertyVal();
if (!is_string($json)) {
$json = json_encode($json);
}
if (!$json || $json == 'null') {
$json = '';
}
return $json;
} | [
"public",
"function",
"jsonVal",
"(",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"propertyVal",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"json",
")",
")",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"json",
")",
";",
"}",
"if",
"(",
"!",
"$",
"json",
"||",
"$",
"json",
"==",
"'null'",
")",
"{",
"$",
"json",
"=",
"''",
";",
"}",
"return",
"$",
"json",
";",
"}"
]
| Retrieve the property's value as a json encoded string.
@return string | [
"Retrieve",
"the",
"property",
"s",
"value",
"as",
"a",
"json",
"encoded",
"string",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/JsonEditorInput.php#L112-L122 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.setupElfinder | public function setupElfinder(array $extraOptions = [])
{
if (!defined('ELFINDER_IMG_PARENT_URL')) {
// Ensure images injected by elFinder are relative to its assets directory
define('ELFINDER_IMG_PARENT_URL', $this->baseUrl(ElfinderTemplate::ELFINDER_ASSETS_REL_PATH));
}
$options = $this->buildConnectorOptions($extraOptions);
// Run elFinder
$connector = new elFinderConnector(new elFinder($options));
$connector->run();
return $connector;
} | php | public function setupElfinder(array $extraOptions = [])
{
if (!defined('ELFINDER_IMG_PARENT_URL')) {
// Ensure images injected by elFinder are relative to its assets directory
define('ELFINDER_IMG_PARENT_URL', $this->baseUrl(ElfinderTemplate::ELFINDER_ASSETS_REL_PATH));
}
$options = $this->buildConnectorOptions($extraOptions);
// Run elFinder
$connector = new elFinderConnector(new elFinder($options));
$connector->run();
return $connector;
} | [
"public",
"function",
"setupElfinder",
"(",
"array",
"$",
"extraOptions",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'ELFINDER_IMG_PARENT_URL'",
")",
")",
"{",
"// Ensure images injected by elFinder are relative to its assets directory",
"define",
"(",
"'ELFINDER_IMG_PARENT_URL'",
",",
"$",
"this",
"->",
"baseUrl",
"(",
"ElfinderTemplate",
"::",
"ELFINDER_ASSETS_REL_PATH",
")",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"buildConnectorOptions",
"(",
"$",
"extraOptions",
")",
";",
"// Run elFinder",
"$",
"connector",
"=",
"new",
"elFinderConnector",
"(",
"new",
"elFinder",
"(",
"$",
"options",
")",
")",
";",
"$",
"connector",
"->",
"run",
"(",
")",
";",
"return",
"$",
"connector",
";",
"}"
]
| Setup the elFinder connector.
@param array|null $extraOptions Additional settings to pass to elFinder.
@return elFinderConnector | [
"Setup",
"the",
"elFinder",
"connector",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L191-L205 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getConnectorOptions | public function getConnectorOptions()
{
if ($this->elfinderOptions === null) {
$this->elfinderOptions = $this->buildConnectorOptions();
}
return $this->elfinderOptions;
} | php | public function getConnectorOptions()
{
if ($this->elfinderOptions === null) {
$this->elfinderOptions = $this->buildConnectorOptions();
}
return $this->elfinderOptions;
} | [
"public",
"function",
"getConnectorOptions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"elfinderOptions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"elfinderOptions",
"=",
"$",
"this",
"->",
"buildConnectorOptions",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"elfinderOptions",
";",
"}"
]
| Retrieve the elFinder Connector options.
@return array | [
"Retrieve",
"the",
"elFinder",
"Connector",
"options",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L212-L219 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.buildConnectorOptions | public function buildConnectorOptions(array $extraOptions = [])
{
$options = [
'debug' => false,
'roots' => $this->getCurrentRoots()
];
$adminOptions = $this->getAdminConnectorOptions();
$adminOptions = $this->parseAdminOptionsForConnectorBuild($adminOptions);
$extraOptions = $this->parseExtraOptionsForConnectorBuild($extraOptions);
$options = $this->mergeConnectorOptions($options, $adminOptions);
$options = $this->mergeConnectorOptions($options, $extraOptions);
if (isset($options['bind'])) {
$options['bind'] = $this->resolveCallbacksForBindOption($options['bind']);
}
$this->elfinderOptions = $options;
return $options;
} | php | public function buildConnectorOptions(array $extraOptions = [])
{
$options = [
'debug' => false,
'roots' => $this->getCurrentRoots()
];
$adminOptions = $this->getAdminConnectorOptions();
$adminOptions = $this->parseAdminOptionsForConnectorBuild($adminOptions);
$extraOptions = $this->parseExtraOptionsForConnectorBuild($extraOptions);
$options = $this->mergeConnectorOptions($options, $adminOptions);
$options = $this->mergeConnectorOptions($options, $extraOptions);
if (isset($options['bind'])) {
$options['bind'] = $this->resolveCallbacksForBindOption($options['bind']);
}
$this->elfinderOptions = $options;
return $options;
} | [
"public",
"function",
"buildConnectorOptions",
"(",
"array",
"$",
"extraOptions",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"[",
"'debug'",
"=>",
"false",
",",
"'roots'",
"=>",
"$",
"this",
"->",
"getCurrentRoots",
"(",
")",
"]",
";",
"$",
"adminOptions",
"=",
"$",
"this",
"->",
"getAdminConnectorOptions",
"(",
")",
";",
"$",
"adminOptions",
"=",
"$",
"this",
"->",
"parseAdminOptionsForConnectorBuild",
"(",
"$",
"adminOptions",
")",
";",
"$",
"extraOptions",
"=",
"$",
"this",
"->",
"parseExtraOptionsForConnectorBuild",
"(",
"$",
"extraOptions",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"mergeConnectorOptions",
"(",
"$",
"options",
",",
"$",
"adminOptions",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"mergeConnectorOptions",
"(",
"$",
"options",
",",
"$",
"extraOptions",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'bind'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'bind'",
"]",
"=",
"$",
"this",
"->",
"resolveCallbacksForBindOption",
"(",
"$",
"options",
"[",
"'bind'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"elfinderOptions",
"=",
"$",
"options",
";",
"return",
"$",
"options",
";",
"}"
]
| Build and retrieve the elFinder Connector options.
@link https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
Documentation for connector options.
@example https://gist.github.com/mcaskill/5944478b1894a5bf1349bfa699387cd4
The Connector can be customized by defining a "elfinder" structure in
your application's admin configuration.
@param array $extraOptions Additional settings to pass to elFinder.
@return array | [
"Build",
"and",
"retrieve",
"the",
"elFinder",
"Connector",
"options",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L233-L254 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getNamedRoot | public function getNamedRoot($ident)
{
if ($this->hasFilesystem($ident) === false) {
return null;
}
$filesystem = $this->getFilesystem($ident);
$fsConfig = $this->getFilesystemConfig($ident);
$elfConfig = $this->getFilesystemAdminConfig($ident);
if (isset($elfConfig['label'])) {
$label = $elfConfig['label'];
} elseif (isset($fsConfig['label'])) {
$label = $fsConfig['label'];
} else {
$label = 'filesystem.disk.'.$ident;
}
$immutableSettings = [
'filesystem' => $filesystem,
'alias' => $this->translator()->translate($label),
];
$root = array_replace_recursive(
$this->getDefaultElfinderRootSettings(),
$this->getDefaultFlysystemRootSettings(),
$elfConfig
);
$root = array_replace_recursive(
$this->resolveFallbackRootSettings($ident),
$root,
$immutableSettings
);
return $this->resolveCallbacksForRoot($root);
} | php | public function getNamedRoot($ident)
{
if ($this->hasFilesystem($ident) === false) {
return null;
}
$filesystem = $this->getFilesystem($ident);
$fsConfig = $this->getFilesystemConfig($ident);
$elfConfig = $this->getFilesystemAdminConfig($ident);
if (isset($elfConfig['label'])) {
$label = $elfConfig['label'];
} elseif (isset($fsConfig['label'])) {
$label = $fsConfig['label'];
} else {
$label = 'filesystem.disk.'.$ident;
}
$immutableSettings = [
'filesystem' => $filesystem,
'alias' => $this->translator()->translate($label),
];
$root = array_replace_recursive(
$this->getDefaultElfinderRootSettings(),
$this->getDefaultFlysystemRootSettings(),
$elfConfig
);
$root = array_replace_recursive(
$this->resolveFallbackRootSettings($ident),
$root,
$immutableSettings
);
return $this->resolveCallbacksForRoot($root);
} | [
"public",
"function",
"getNamedRoot",
"(",
"$",
"ident",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasFilesystem",
"(",
"$",
"ident",
")",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"filesystem",
"=",
"$",
"this",
"->",
"getFilesystem",
"(",
"$",
"ident",
")",
";",
"$",
"fsConfig",
"=",
"$",
"this",
"->",
"getFilesystemConfig",
"(",
"$",
"ident",
")",
";",
"$",
"elfConfig",
"=",
"$",
"this",
"->",
"getFilesystemAdminConfig",
"(",
"$",
"ident",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"elfConfig",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"label",
"=",
"$",
"elfConfig",
"[",
"'label'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"fsConfig",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"label",
"=",
"$",
"fsConfig",
"[",
"'label'",
"]",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"'filesystem.disk.'",
".",
"$",
"ident",
";",
"}",
"$",
"immutableSettings",
"=",
"[",
"'filesystem'",
"=>",
"$",
"filesystem",
",",
"'alias'",
"=>",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translate",
"(",
"$",
"label",
")",
",",
"]",
";",
"$",
"root",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"getDefaultElfinderRootSettings",
"(",
")",
",",
"$",
"this",
"->",
"getDefaultFlysystemRootSettings",
"(",
")",
",",
"$",
"elfConfig",
")",
";",
"$",
"root",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"resolveFallbackRootSettings",
"(",
"$",
"ident",
")",
",",
"$",
"root",
",",
"$",
"immutableSettings",
")",
";",
"return",
"$",
"this",
"->",
"resolveCallbacksForRoot",
"(",
"$",
"root",
")",
";",
"}"
]
| Retrieve the elFinder root options for the given file system.
Merges `config.filesystem.connections` with
{@see self::getDefaultDiskSettings() default root settings}.
@param string $ident The disk identifier.
@return array|null Returns an elFinder root structure or NULL. | [
"Retrieve",
"the",
"elFinder",
"root",
"options",
"for",
"the",
"given",
"file",
"system",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L390-L426 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getPublicRoots | public function getPublicRoots()
{
$roots = [];
foreach ($this->filesystems->keys() as $ident) {
if ($this->isFilesystemPublic($ident)) {
$disk = $this->getNamedRoot($ident);
if ($disk !== null) {
$roots[$ident] = $disk;
}
}
}
return $roots;
} | php | public function getPublicRoots()
{
$roots = [];
foreach ($this->filesystems->keys() as $ident) {
if ($this->isFilesystemPublic($ident)) {
$disk = $this->getNamedRoot($ident);
if ($disk !== null) {
$roots[$ident] = $disk;
}
}
}
return $roots;
} | [
"public",
"function",
"getPublicRoots",
"(",
")",
"{",
"$",
"roots",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"filesystems",
"->",
"keys",
"(",
")",
"as",
"$",
"ident",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFilesystemPublic",
"(",
"$",
"ident",
")",
")",
"{",
"$",
"disk",
"=",
"$",
"this",
"->",
"getNamedRoot",
"(",
"$",
"ident",
")",
";",
"if",
"(",
"$",
"disk",
"!==",
"null",
")",
"{",
"$",
"roots",
"[",
"$",
"ident",
"]",
"=",
"$",
"disk",
";",
"}",
"}",
"}",
"return",
"$",
"roots",
";",
"}"
]
| Retrieve only the public elFinder root volumes.
@return array | [
"Retrieve",
"only",
"the",
"public",
"elFinder",
"root",
"volumes",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L433-L446 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getAllRoots | public function getAllRoots()
{
$roots = [];
foreach ($this->filesystems->keys() as $ident) {
$disk = $this->getNamedRoot($ident);
if ($disk !== null) {
$roots[$ident] = $disk;
}
}
return $roots;
} | php | public function getAllRoots()
{
$roots = [];
foreach ($this->filesystems->keys() as $ident) {
$disk = $this->getNamedRoot($ident);
if ($disk !== null) {
$roots[$ident] = $disk;
}
}
return $roots;
} | [
"public",
"function",
"getAllRoots",
"(",
")",
"{",
"$",
"roots",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"filesystems",
"->",
"keys",
"(",
")",
"as",
"$",
"ident",
")",
"{",
"$",
"disk",
"=",
"$",
"this",
"->",
"getNamedRoot",
"(",
"$",
"ident",
")",
";",
"if",
"(",
"$",
"disk",
"!==",
"null",
")",
"{",
"$",
"roots",
"[",
"$",
"ident",
"]",
"=",
"$",
"disk",
";",
"}",
"}",
"return",
"$",
"roots",
";",
"}"
]
| Retrieve all elFinder root volumes.
@return array | [
"Retrieve",
"all",
"elFinder",
"root",
"volumes",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L453-L464 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getCurrentRoots | public function getCurrentRoots()
{
$formProperty = $this->formProperty();
$targetFilesystem = $formProperty ? $formProperty->filesystem() : null;
if ($this->hasFilesystem($targetFilesystem)) {
$disk = $this->getNamedRoot($targetFilesystem);
$startPath = $formProperty->uploadPath();
$isPublic = $formProperty->publicAccess();
$basePath = $isPublic ? $this->publicPath : $this->basePath;
if (!file_exists($basePath.$startPath)) {
mkdir($basePath.$startPath, 0755, true);
}
if ($startPath) {
$disk['startPath'] = $startPath;
}
return [ $disk ];
}
return $this->getPublicRoots();
} | php | public function getCurrentRoots()
{
$formProperty = $this->formProperty();
$targetFilesystem = $formProperty ? $formProperty->filesystem() : null;
if ($this->hasFilesystem($targetFilesystem)) {
$disk = $this->getNamedRoot($targetFilesystem);
$startPath = $formProperty->uploadPath();
$isPublic = $formProperty->publicAccess();
$basePath = $isPublic ? $this->publicPath : $this->basePath;
if (!file_exists($basePath.$startPath)) {
mkdir($basePath.$startPath, 0755, true);
}
if ($startPath) {
$disk['startPath'] = $startPath;
}
return [ $disk ];
}
return $this->getPublicRoots();
} | [
"public",
"function",
"getCurrentRoots",
"(",
")",
"{",
"$",
"formProperty",
"=",
"$",
"this",
"->",
"formProperty",
"(",
")",
";",
"$",
"targetFilesystem",
"=",
"$",
"formProperty",
"?",
"$",
"formProperty",
"->",
"filesystem",
"(",
")",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"hasFilesystem",
"(",
"$",
"targetFilesystem",
")",
")",
"{",
"$",
"disk",
"=",
"$",
"this",
"->",
"getNamedRoot",
"(",
"$",
"targetFilesystem",
")",
";",
"$",
"startPath",
"=",
"$",
"formProperty",
"->",
"uploadPath",
"(",
")",
";",
"$",
"isPublic",
"=",
"$",
"formProperty",
"->",
"publicAccess",
"(",
")",
";",
"$",
"basePath",
"=",
"$",
"isPublic",
"?",
"$",
"this",
"->",
"publicPath",
":",
"$",
"this",
"->",
"basePath",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"basePath",
".",
"$",
"startPath",
")",
")",
"{",
"mkdir",
"(",
"$",
"basePath",
".",
"$",
"startPath",
",",
"0755",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"startPath",
")",
"{",
"$",
"disk",
"[",
"'startPath'",
"]",
"=",
"$",
"startPath",
";",
"}",
"return",
"[",
"$",
"disk",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"getPublicRoots",
"(",
")",
";",
"}"
]
| Retrieve only the current context's elFinder root volumes.
@return array Returns all public root volumes
or a subset if the context has a related form property. | [
"Retrieve",
"only",
"the",
"current",
"context",
"s",
"elFinder",
"root",
"volumes",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L472-L496 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.resolveCallbacksForRoots | protected function resolveCallbacksForRoots(array $roots)
{
foreach ($roots as $i => $root) {
$roots[$i] = $this->resolveCallbacksForRoot($root);
}
return $roots;
} | php | protected function resolveCallbacksForRoots(array $roots)
{
foreach ($roots as $i => $root) {
$roots[$i] = $this->resolveCallbacksForRoot($root);
}
return $roots;
} | [
"protected",
"function",
"resolveCallbacksForRoots",
"(",
"array",
"$",
"roots",
")",
"{",
"foreach",
"(",
"$",
"roots",
"as",
"$",
"i",
"=>",
"$",
"root",
")",
"{",
"$",
"roots",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"resolveCallbacksForRoot",
"(",
"$",
"root",
")",
";",
"}",
"return",
"$",
"roots",
";",
"}"
]
| Resolve callables in a collection of elFinder's root volumes.
@param array $roots One or many roots with possible unresolved callables.
@return array Returns the root(s) with resolved callables. | [
"Resolve",
"callables",
"in",
"a",
"collection",
"of",
"elFinder",
"s",
"root",
"volumes",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L504-L511 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.resolveCallbacksForRoot | protected function resolveCallbacksForRoot(array $root)
{
if (isset($root['accessControl'])) {
$callable = $root['accessControl'];
if (!is_callable($callable) && is_string($callable)) {
$root['accessControl'] = $this->resolveCallable($callable);
}
}
return $root;
} | php | protected function resolveCallbacksForRoot(array $root)
{
if (isset($root['accessControl'])) {
$callable = $root['accessControl'];
if (!is_callable($callable) && is_string($callable)) {
$root['accessControl'] = $this->resolveCallable($callable);
}
}
return $root;
} | [
"protected",
"function",
"resolveCallbacksForRoot",
"(",
"array",
"$",
"root",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"root",
"[",
"'accessControl'",
"]",
")",
")",
"{",
"$",
"callable",
"=",
"$",
"root",
"[",
"'accessControl'",
"]",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callable",
")",
"&&",
"is_string",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"root",
"[",
"'accessControl'",
"]",
"=",
"$",
"this",
"->",
"resolveCallable",
"(",
"$",
"callable",
")",
";",
"}",
"}",
"return",
"$",
"root",
";",
"}"
]
| Resolve callables in one elFinder root volume.
@param array $root A root structure with possible unresolved callables.
@return array Returns the root with resolved callables. | [
"Resolve",
"callables",
"in",
"one",
"elFinder",
"root",
"volume",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L519-L529 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.resolveCallbacksForBindOption | protected function resolveCallbacksForBindOption(array $toResolve)
{
$resolved = $toResolve;
foreach ($toResolve as $actions => $callables) {
foreach ($callables as $i => $callable) {
if (!is_callable($callable) && is_string($callable)) {
if (0 === strpos($callable, 'Plugin.')) {
continue;
}
$resolved[$actions][$i] = $this->resolveCallable($callable);
}
}
}
return $resolved;
} | php | protected function resolveCallbacksForBindOption(array $toResolve)
{
$resolved = $toResolve;
foreach ($toResolve as $actions => $callables) {
foreach ($callables as $i => $callable) {
if (!is_callable($callable) && is_string($callable)) {
if (0 === strpos($callable, 'Plugin.')) {
continue;
}
$resolved[$actions][$i] = $this->resolveCallable($callable);
}
}
}
return $resolved;
} | [
"protected",
"function",
"resolveCallbacksForBindOption",
"(",
"array",
"$",
"toResolve",
")",
"{",
"$",
"resolved",
"=",
"$",
"toResolve",
";",
"foreach",
"(",
"$",
"toResolve",
"as",
"$",
"actions",
"=>",
"$",
"callables",
")",
"{",
"foreach",
"(",
"$",
"callables",
"as",
"$",
"i",
"=>",
"$",
"callable",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callable",
")",
"&&",
"is_string",
"(",
"$",
"callable",
")",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"callable",
",",
"'Plugin.'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"resolved",
"[",
"$",
"actions",
"]",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"resolveCallable",
"(",
"$",
"callable",
")",
";",
"}",
"}",
"}",
"return",
"$",
"resolved",
";",
"}"
]
| Resolve callables in elFinder's "bind" option.
@param array $toResolve One or many pairs of callbacks.
@return array Returns the parsed event listeners. | [
"Resolve",
"callables",
"in",
"elFinder",
"s",
"bind",
"option",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L537-L554 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.sanitizeOnUploadPreSave | public function sanitizeOnUploadPreSave(&$path, &$name, $src, $elfinder, $volume)
{
// To please PHPCS
unset($path, $src, $elfinder, $volume);
if (isset($this->elfinderOptions['plugin']['Sanitizer'])) {
$opts = $this->elfinderOptions['plugin']['Sanitizer'];
if (isset($opts['enable']) && $opts['enable']) {
$mask = (is_array($opts['replace']) ? implode($opts['replace']) : $opts['replace']);
$ext = '.'.pathinfo($name, PATHINFO_EXTENSION);
// Strip leading and trailing dashes or underscores
$name = trim(str_replace($ext, '', $name), $mask);
// Squeeze multiple delimiters and whitespace with a single separator
$name = preg_replace('!['.preg_quote($mask, '!').'\.\s]{2,}!', $opts['replace'], $name);
// Reassemble the file name
$name .= $ext;
}
}
return true;
} | php | public function sanitizeOnUploadPreSave(&$path, &$name, $src, $elfinder, $volume)
{
// To please PHPCS
unset($path, $src, $elfinder, $volume);
if (isset($this->elfinderOptions['plugin']['Sanitizer'])) {
$opts = $this->elfinderOptions['plugin']['Sanitizer'];
if (isset($opts['enable']) && $opts['enable']) {
$mask = (is_array($opts['replace']) ? implode($opts['replace']) : $opts['replace']);
$ext = '.'.pathinfo($name, PATHINFO_EXTENSION);
// Strip leading and trailing dashes or underscores
$name = trim(str_replace($ext, '', $name), $mask);
// Squeeze multiple delimiters and whitespace with a single separator
$name = preg_replace('!['.preg_quote($mask, '!').'\.\s]{2,}!', $opts['replace'], $name);
// Reassemble the file name
$name .= $ext;
}
}
return true;
} | [
"public",
"function",
"sanitizeOnUploadPreSave",
"(",
"&",
"$",
"path",
",",
"&",
"$",
"name",
",",
"$",
"src",
",",
"$",
"elfinder",
",",
"$",
"volume",
")",
"{",
"// To please PHPCS",
"unset",
"(",
"$",
"path",
",",
"$",
"src",
",",
"$",
"elfinder",
",",
"$",
"volume",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"elfinderOptions",
"[",
"'plugin'",
"]",
"[",
"'Sanitizer'",
"]",
")",
")",
"{",
"$",
"opts",
"=",
"$",
"this",
"->",
"elfinderOptions",
"[",
"'plugin'",
"]",
"[",
"'Sanitizer'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"opts",
"[",
"'enable'",
"]",
")",
"&&",
"$",
"opts",
"[",
"'enable'",
"]",
")",
"{",
"$",
"mask",
"=",
"(",
"is_array",
"(",
"$",
"opts",
"[",
"'replace'",
"]",
")",
"?",
"implode",
"(",
"$",
"opts",
"[",
"'replace'",
"]",
")",
":",
"$",
"opts",
"[",
"'replace'",
"]",
")",
";",
"$",
"ext",
"=",
"'.'",
".",
"pathinfo",
"(",
"$",
"name",
",",
"PATHINFO_EXTENSION",
")",
";",
"// Strip leading and trailing dashes or underscores",
"$",
"name",
"=",
"trim",
"(",
"str_replace",
"(",
"$",
"ext",
",",
"''",
",",
"$",
"name",
")",
",",
"$",
"mask",
")",
";",
"// Squeeze multiple delimiters and whitespace with a single separator",
"$",
"name",
"=",
"preg_replace",
"(",
"'!['",
".",
"preg_quote",
"(",
"$",
"mask",
",",
"'!'",
")",
".",
"'\\.\\s]{2,}!'",
",",
"$",
"opts",
"[",
"'replace'",
"]",
",",
"$",
"name",
")",
";",
"// Reassemble the file name",
"$",
"name",
".=",
"$",
"ext",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Trim a file name.
@param string $path The target path.
@param string $name The target name.
@param string $src The temporary file name.
@param object $elfinder The elFinder instance.
@param object $volume The current volume instance.
@return true | [
"Trim",
"a",
"file",
"name",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L566-L590 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.checkAccess | public function checkAccess($attr, $path, $data, elFinderVolumeDriver $volume, $isDir, $relPath)
{
unset($data, $volume, $isDir);
$basename = basename($path);
/**
* If file/folder begins with '.' (dot) but without volume root,
* set to FALSE if attributes are "read" or "write",
* set to TRUE if attributes are other ("locked" + "hidden"),
* set to NULL to let elFinder decide itself.
*/
return ($basename[0] === '.' && strlen($relPath) !== 1)
? !($attr === 'read' || $attr === 'write')
: null;
} | php | public function checkAccess($attr, $path, $data, elFinderVolumeDriver $volume, $isDir, $relPath)
{
unset($data, $volume, $isDir);
$basename = basename($path);
/**
* If file/folder begins with '.' (dot) but without volume root,
* set to FALSE if attributes are "read" or "write",
* set to TRUE if attributes are other ("locked" + "hidden"),
* set to NULL to let elFinder decide itself.
*/
return ($basename[0] === '.' && strlen($relPath) !== 1)
? !($attr === 'read' || $attr === 'write')
: null;
} | [
"public",
"function",
"checkAccess",
"(",
"$",
"attr",
",",
"$",
"path",
",",
"$",
"data",
",",
"elFinderVolumeDriver",
"$",
"volume",
",",
"$",
"isDir",
",",
"$",
"relPath",
")",
"{",
"unset",
"(",
"$",
"data",
",",
"$",
"volume",
",",
"$",
"isDir",
")",
";",
"$",
"basename",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"/**\n * If file/folder begins with '.' (dot) but without volume root,\n * set to FALSE if attributes are \"read\" or \"write\",\n * set to TRUE if attributes are other (\"locked\" + \"hidden\"),\n * set to NULL to let elFinder decide itself.\n */",
"return",
"(",
"$",
"basename",
"[",
"0",
"]",
"===",
"'.'",
"&&",
"strlen",
"(",
"$",
"relPath",
")",
"!==",
"1",
")",
"?",
"!",
"(",
"$",
"attr",
"===",
"'read'",
"||",
"$",
"attr",
"===",
"'write'",
")",
":",
"null",
";",
"}"
]
| Control file access.
This method will disable accessing files/folders starting from '.' (dot)
@param string $attr Attribute name ("read", "write", "locked", "hidden").
@param string $path Absolute file path.
@param string $data Value of volume option `accessControlData`.
@param \elFinderVolumeDriver $volume ElFinder volume driver object.
@param boolean|null $isDir Whether the path is a directory
(TRUE: directory, FALSE: file, NULL: unknown).
@param string $relPath File path relative to the volume root directory
started with directory separator.
@return boolean|null TRUE to allow, FALSE to deny, NULL to let elFinder decide. | [
"Control",
"file",
"access",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L607-L621 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getFilesystem | protected function getFilesystem($ident)
{
if (isset($this->filesystems[$ident])) {
return $this->filesystems[$ident];
}
return null;
} | php | protected function getFilesystem($ident)
{
if (isset($this->filesystems[$ident])) {
return $this->filesystems[$ident];
}
return null;
} | [
"protected",
"function",
"getFilesystem",
"(",
"$",
"ident",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filesystems",
"[",
"$",
"ident",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filesystems",
"[",
"$",
"ident",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Get the named filesystem object.
@param string $ident The filesystem identifier.
@return \League\Flysystem\FilesystemInterface|null Returns the filesystem instance
or NULL if not found. | [
"Get",
"the",
"named",
"filesystem",
"object",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L769-L776 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getFilesystemConfig | protected function getFilesystemConfig($ident)
{
if ($this->hasFilesystem($ident) === false) {
return null;
}
if (isset($this->filesystemConfig['connections'][$ident])) {
return $this->filesystemConfig['connections'][$ident];
}
return [];
} | php | protected function getFilesystemConfig($ident)
{
if ($this->hasFilesystem($ident) === false) {
return null;
}
if (isset($this->filesystemConfig['connections'][$ident])) {
return $this->filesystemConfig['connections'][$ident];
}
return [];
} | [
"protected",
"function",
"getFilesystemConfig",
"(",
"$",
"ident",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasFilesystem",
"(",
"$",
"ident",
")",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filesystemConfig",
"[",
"'connections'",
"]",
"[",
"$",
"ident",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filesystemConfig",
"[",
"'connections'",
"]",
"[",
"$",
"ident",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
]
| Get the given filesystem's storage configset.
@param string $ident The filesystem identifier.
@return array|null Returns the filesystem configset
or NULL if the filesystem is not found. | [
"Get",
"the",
"given",
"filesystem",
"s",
"storage",
"configset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L796-L807 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.getFilesystemAdminConfig | protected function getFilesystemAdminConfig($ident)
{
if ($this->hasFilesystem($ident) === false) {
return null;
}
$elfConfig = $this->getAdminConnectorOptions();
if (isset($elfConfig['roots'][$ident])) {
return $elfConfig['roots'][$ident];
}
return [];
} | php | protected function getFilesystemAdminConfig($ident)
{
if ($this->hasFilesystem($ident) === false) {
return null;
}
$elfConfig = $this->getAdminConnectorOptions();
if (isset($elfConfig['roots'][$ident])) {
return $elfConfig['roots'][$ident];
}
return [];
} | [
"protected",
"function",
"getFilesystemAdminConfig",
"(",
"$",
"ident",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasFilesystem",
"(",
"$",
"ident",
")",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"elfConfig",
"=",
"$",
"this",
"->",
"getAdminConnectorOptions",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"elfConfig",
"[",
"'roots'",
"]",
"[",
"$",
"ident",
"]",
")",
")",
"{",
"return",
"$",
"elfConfig",
"[",
"'roots'",
"]",
"[",
"$",
"ident",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
]
| Get the given filesystem's admin configset.
@param string $ident The filesystem identifier.
@return array|null Returns the filesystem configset
or NULL if the filesystem is not found. | [
"Get",
"the",
"given",
"filesystem",
"s",
"admin",
"configset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L836-L848 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/ElfinderConnectorAction.php | ElfinderConnectorAction.elfinderConfig | protected function elfinderConfig($key = null, $default = null)
{
if ($key) {
if (isset($this->elfinderConfig[$key])) {
return $this->elfinderConfig[$key];
} else {
if (!is_string($default) && is_callable($default)) {
return $default();
} else {
return $default;
}
}
}
return $this->elfinderConfig;
} | php | protected function elfinderConfig($key = null, $default = null)
{
if ($key) {
if (isset($this->elfinderConfig[$key])) {
return $this->elfinderConfig[$key];
} else {
if (!is_string($default) && is_callable($default)) {
return $default();
} else {
return $default;
}
}
}
return $this->elfinderConfig;
} | [
"protected",
"function",
"elfinderConfig",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"elfinderConfig",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"elfinderConfig",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"default",
")",
"&&",
"is_callable",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"elfinderConfig",
";",
"}"
]
| Retrieve the elFinder's configset.
@param string|null $key Optional data key to retrieve from the configset.
@param mixed|null $default The default value to return if data key does not exist.
@return mixed|AdminConfig | [
"Retrieve",
"the",
"elFinder",
"s",
"configset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/ElfinderConnectorAction.php#L868-L883 | train |
acquia/commerce-manager | modules/acm_promotion/src/AcmPromotionsManager.php | AcmPromotionsManager.syncPromotions | public function syncPromotions($types = ['category', 'cart']) {
$types = is_array($types) ? $types : [$types];
$ids = [];
$fetched_promotions = [];
foreach ($types as $type) {
$promotions = $this->apiWrapper->getPromotions($type);
foreach ($promotions as $key => $promotion) {
// Add type to $promotion array, to be saved later.
$promotion['promotion_type'] = $type;
$fetched_promotions[] = $promotion;
$ids[] = $promotion['rule_id'];
}
}
if (!empty($fetched_promotions)) {
$this->processPromotions($fetched_promotions);
}
// Delete promotions, which are not part of API response.
if (!empty($ids)) {
$this->deletePromotions($types, $ids);
}
} | php | public function syncPromotions($types = ['category', 'cart']) {
$types = is_array($types) ? $types : [$types];
$ids = [];
$fetched_promotions = [];
foreach ($types as $type) {
$promotions = $this->apiWrapper->getPromotions($type);
foreach ($promotions as $key => $promotion) {
// Add type to $promotion array, to be saved later.
$promotion['promotion_type'] = $type;
$fetched_promotions[] = $promotion;
$ids[] = $promotion['rule_id'];
}
}
if (!empty($fetched_promotions)) {
$this->processPromotions($fetched_promotions);
}
// Delete promotions, which are not part of API response.
if (!empty($ids)) {
$this->deletePromotions($types, $ids);
}
} | [
"public",
"function",
"syncPromotions",
"(",
"$",
"types",
"=",
"[",
"'category'",
",",
"'cart'",
"]",
")",
"{",
"$",
"types",
"=",
"is_array",
"(",
"$",
"types",
")",
"?",
"$",
"types",
":",
"[",
"$",
"types",
"]",
";",
"$",
"ids",
"=",
"[",
"]",
";",
"$",
"fetched_promotions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"promotions",
"=",
"$",
"this",
"->",
"apiWrapper",
"->",
"getPromotions",
"(",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"promotions",
"as",
"$",
"key",
"=>",
"$",
"promotion",
")",
"{",
"// Add type to $promotion array, to be saved later.",
"$",
"promotion",
"[",
"'promotion_type'",
"]",
"=",
"$",
"type",
";",
"$",
"fetched_promotions",
"[",
"]",
"=",
"$",
"promotion",
";",
"$",
"ids",
"[",
"]",
"=",
"$",
"promotion",
"[",
"'rule_id'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"fetched_promotions",
")",
")",
"{",
"$",
"this",
"->",
"processPromotions",
"(",
"$",
"fetched_promotions",
")",
";",
"}",
"// Delete promotions, which are not part of API response.",
"if",
"(",
"!",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"$",
"this",
"->",
"deletePromotions",
"(",
"$",
"types",
",",
"$",
"ids",
")",
";",
"}",
"}"
]
| Synchronize promotions through the API.
@param mixed $types
The type of promotion to synchronize. | [
"Synchronize",
"promotions",
"through",
"the",
"API",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/AcmPromotionsManager.php#L139-L163 | train |
acquia/commerce-manager | modules/acm_promotion/src/AcmPromotionsManager.php | AcmPromotionsManager.deletePromotions | protected function deletePromotions(array $types, array $validIDs = []) {
$query = $this->nodeStorage->getQuery();
$query->condition('type', 'acm_promotion');
$query->condition('field_acm_promotion_type', $types, 'IN');
if ($validIDs) {
$query->condition('field_acm_promotion_rule_id', $validIDs, 'NOT IN');
}
$nids = $query->execute();
foreach ($nids as $nid) {
/* @var $node \Drupal\node\NodeInterface */
$node = $this->nodeStorage->load($nid);
if ($node instanceof NodeInterface) {
$node->delete();
$this->logger->notice('Deleted orphan promotion node @promotion having rule_id:@rule_id.', [
'@promotion' => $node->label(),
'@rule_id' => $node->get('field_acm_promotion_rule_id')->first()->getString(),
]);
}
}
} | php | protected function deletePromotions(array $types, array $validIDs = []) {
$query = $this->nodeStorage->getQuery();
$query->condition('type', 'acm_promotion');
$query->condition('field_acm_promotion_type', $types, 'IN');
if ($validIDs) {
$query->condition('field_acm_promotion_rule_id', $validIDs, 'NOT IN');
}
$nids = $query->execute();
foreach ($nids as $nid) {
/* @var $node \Drupal\node\NodeInterface */
$node = $this->nodeStorage->load($nid);
if ($node instanceof NodeInterface) {
$node->delete();
$this->logger->notice('Deleted orphan promotion node @promotion having rule_id:@rule_id.', [
'@promotion' => $node->label(),
'@rule_id' => $node->get('field_acm_promotion_rule_id')->first()->getString(),
]);
}
}
} | [
"protected",
"function",
"deletePromotions",
"(",
"array",
"$",
"types",
",",
"array",
"$",
"validIDs",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"nodeStorage",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'type'",
",",
"'acm_promotion'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'field_acm_promotion_type'",
",",
"$",
"types",
",",
"'IN'",
")",
";",
"if",
"(",
"$",
"validIDs",
")",
"{",
"$",
"query",
"->",
"condition",
"(",
"'field_acm_promotion_rule_id'",
",",
"$",
"validIDs",
",",
"'NOT IN'",
")",
";",
"}",
"$",
"nids",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"foreach",
"(",
"$",
"nids",
"as",
"$",
"nid",
")",
"{",
"/* @var $node \\Drupal\\node\\NodeInterface */",
"$",
"node",
"=",
"$",
"this",
"->",
"nodeStorage",
"->",
"load",
"(",
"$",
"nid",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"NodeInterface",
")",
"{",
"$",
"node",
"->",
"delete",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"'Deleted orphan promotion node @promotion having rule_id:@rule_id.'",
",",
"[",
"'@promotion'",
"=>",
"$",
"node",
"->",
"label",
"(",
")",
",",
"'@rule_id'",
"=>",
"$",
"node",
"->",
"get",
"(",
"'field_acm_promotion_rule_id'",
")",
"->",
"first",
"(",
")",
"->",
"getString",
"(",
")",
",",
"]",
")",
";",
"}",
"}",
"}"
]
| Delete Promotion nodes, not part of API Response.
@param array $types
Promotions types to delete.
@param array $validIDs
Valid Rule ID's from API. | [
"Delete",
"Promotion",
"nodes",
"not",
"part",
"of",
"API",
"Response",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/AcmPromotionsManager.php#L173-L195 | train |
acquia/commerce-manager | modules/acm_promotion/src/AcmPromotionsManager.php | AcmPromotionsManager.getPromotionByRuleId | public function getPromotionByRuleId($rule_id, $rule_type) {
$query = $this->nodeStorage->getQuery();
$query->condition('type', 'acm_promotion');
$query->condition('field_acm_promotion_rule_id', $rule_id);
$query->condition('field_acm_promotion_type', $rule_type);
$nids = $query->execute();
if (empty($nids)) {
return NULL;
}
else {
// Log a message for admin to check errors in data.
if (count($nids) > 1) {
$this->logger->critical('Multiple nodes found for rule id @rule_id', ['@rule_id' => $rule_id]);
return NULL;
}
// We only load the first node.
/* @var $node \Drupal\node\NodeInterface */
$node = $this->nodeStorage->load(reset($nids));
$langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
// Get the promotion with language fallback, if it did not have a
// translation for $langcode.
$node = $this->entityRepository->getTranslationFromContext($node, $langcode);
return $node;
}
} | php | public function getPromotionByRuleId($rule_id, $rule_type) {
$query = $this->nodeStorage->getQuery();
$query->condition('type', 'acm_promotion');
$query->condition('field_acm_promotion_rule_id', $rule_id);
$query->condition('field_acm_promotion_type', $rule_type);
$nids = $query->execute();
if (empty($nids)) {
return NULL;
}
else {
// Log a message for admin to check errors in data.
if (count($nids) > 1) {
$this->logger->critical('Multiple nodes found for rule id @rule_id', ['@rule_id' => $rule_id]);
return NULL;
}
// We only load the first node.
/* @var $node \Drupal\node\NodeInterface */
$node = $this->nodeStorage->load(reset($nids));
$langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
// Get the promotion with language fallback, if it did not have a
// translation for $langcode.
$node = $this->entityRepository->getTranslationFromContext($node, $langcode);
return $node;
}
} | [
"public",
"function",
"getPromotionByRuleId",
"(",
"$",
"rule_id",
",",
"$",
"rule_type",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"nodeStorage",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'type'",
",",
"'acm_promotion'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'field_acm_promotion_rule_id'",
",",
"$",
"rule_id",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'field_acm_promotion_type'",
",",
"$",
"rule_type",
")",
";",
"$",
"nids",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"nids",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"else",
"{",
"// Log a message for admin to check errors in data.",
"if",
"(",
"count",
"(",
"$",
"nids",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"'Multiple nodes found for rule id @rule_id'",
",",
"[",
"'@rule_id'",
"=>",
"$",
"rule_id",
"]",
")",
";",
"return",
"NULL",
";",
"}",
"// We only load the first node.",
"/* @var $node \\Drupal\\node\\NodeInterface */",
"$",
"node",
"=",
"$",
"this",
"->",
"nodeStorage",
"->",
"load",
"(",
"reset",
"(",
"$",
"nids",
")",
")",
";",
"$",
"langcode",
"=",
"$",
"this",
"->",
"languageManager",
"->",
"getCurrentLanguage",
"(",
"LanguageInterface",
"::",
"TYPE_CONTENT",
")",
"->",
"getId",
"(",
")",
";",
"// Get the promotion with language fallback, if it did not have a",
"// translation for $langcode.",
"$",
"node",
"=",
"$",
"this",
"->",
"entityRepository",
"->",
"getTranslationFromContext",
"(",
"$",
"node",
",",
"$",
"langcode",
")",
";",
"return",
"$",
"node",
";",
"}",
"}"
]
| Helper function to fetch promotion node given rule id.
@param int $rule_id
Rule id of the promotion to load.
@param string $rule_type
Rule type of the promotion to load.
@return \Drupal\node\NodeInterface|null
Return node if a promotion found associated with the rule id else Null. | [
"Helper",
"function",
"to",
"fetch",
"promotion",
"node",
"given",
"rule",
"id",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/AcmPromotionsManager.php#L208-L234 | train |
acquia/commerce-manager | modules/acm_promotion/src/AcmPromotionsManager.php | AcmPromotionsManager.getSkusForPromotion | public function getSkusForPromotion(NodeInterface $promotion) {
$query = $this->connection->select('acm_sku__field_acm_sku_promotions', 'fasp');
if (\Drupal::entityTypeManager()->getDefinition('acm_sku')->isTranslatable()) {
$query->join('acm_sku_field_data', 'asfd', 'asfd.id = fasp.entity_id');
}
else {
$query->join('acm_sku', 'asfd', 'asfd.id = fasp.entity_id');
}
$query->condition('fasp.field_acm_sku_promotions_target_id', $promotion->id());
$query->fields('asfd', ['id', 'sku']);
$query->distinct();
$skus = $query->execute()->fetchAllKeyed(0, 1);
return $skus;
} | php | public function getSkusForPromotion(NodeInterface $promotion) {
$query = $this->connection->select('acm_sku__field_acm_sku_promotions', 'fasp');
if (\Drupal::entityTypeManager()->getDefinition('acm_sku')->isTranslatable()) {
$query->join('acm_sku_field_data', 'asfd', 'asfd.id = fasp.entity_id');
}
else {
$query->join('acm_sku', 'asfd', 'asfd.id = fasp.entity_id');
}
$query->condition('fasp.field_acm_sku_promotions_target_id', $promotion->id());
$query->fields('asfd', ['id', 'sku']);
$query->distinct();
$skus = $query->execute()->fetchAllKeyed(0, 1);
return $skus;
} | [
"public",
"function",
"getSkusForPromotion",
"(",
"NodeInterface",
"$",
"promotion",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"select",
"(",
"'acm_sku__field_acm_sku_promotions'",
",",
"'fasp'",
")",
";",
"if",
"(",
"\\",
"Drupal",
"::",
"entityTypeManager",
"(",
")",
"->",
"getDefinition",
"(",
"'acm_sku'",
")",
"->",
"isTranslatable",
"(",
")",
")",
"{",
"$",
"query",
"->",
"join",
"(",
"'acm_sku_field_data'",
",",
"'asfd'",
",",
"'asfd.id = fasp.entity_id'",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"join",
"(",
"'acm_sku'",
",",
"'asfd'",
",",
"'asfd.id = fasp.entity_id'",
")",
";",
"}",
"$",
"query",
"->",
"condition",
"(",
"'fasp.field_acm_sku_promotions_target_id'",
",",
"$",
"promotion",
"->",
"id",
"(",
")",
")",
";",
"$",
"query",
"->",
"fields",
"(",
"'asfd'",
",",
"[",
"'id'",
",",
"'sku'",
"]",
")",
";",
"$",
"query",
"->",
"distinct",
"(",
")",
";",
"$",
"skus",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAllKeyed",
"(",
"0",
",",
"1",
")",
";",
"return",
"$",
"skus",
";",
"}"
]
| Helper function to get skus attached with a promotion.
@param \Drupal\node\NodeInterface $promotion
Promotion node for which we need to find skus.
@return array
Array of sku objects attached with the promotion. | [
"Helper",
"function",
"to",
"get",
"skus",
"attached",
"with",
"a",
"promotion",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/AcmPromotionsManager.php#L245-L259 | train |
acquia/commerce-manager | modules/acm_promotion/src/AcmPromotionsManager.php | AcmPromotionsManager.removeOrphanPromotionFromSku | public function removeOrphanPromotionFromSku(SKU $sku, int $nid) {
$promotion_detach_item[] = ['target_id' => $nid];
$sku_promotions = $sku->get('field_acm_sku_promotions')->getValue();
$sku_promotions = array_udiff($sku_promotions, $promotion_detach_item, function ($array1, $array2) {
return $array1['target_id'] - $array2['target_id'];
});
$sku->get('field_acm_sku_promotions')->setValue($sku_promotions);
$sku->save();
// Update Sku Translations.
$translation_languages = $sku->getTranslationLanguages(TRUE);
if (!empty($translation_languages)) {
foreach ($translation_languages as $langcode => $language) {
$sku_entity_translation = $sku->getTranslation($langcode);
$sku_entity_translation->get('field_acm_sku_promotions')->setValue($sku_promotions);
$sku_entity_translation->save();
}
}
} | php | public function removeOrphanPromotionFromSku(SKU $sku, int $nid) {
$promotion_detach_item[] = ['target_id' => $nid];
$sku_promotions = $sku->get('field_acm_sku_promotions')->getValue();
$sku_promotions = array_udiff($sku_promotions, $promotion_detach_item, function ($array1, $array2) {
return $array1['target_id'] - $array2['target_id'];
});
$sku->get('field_acm_sku_promotions')->setValue($sku_promotions);
$sku->save();
// Update Sku Translations.
$translation_languages = $sku->getTranslationLanguages(TRUE);
if (!empty($translation_languages)) {
foreach ($translation_languages as $langcode => $language) {
$sku_entity_translation = $sku->getTranslation($langcode);
$sku_entity_translation->get('field_acm_sku_promotions')->setValue($sku_promotions);
$sku_entity_translation->save();
}
}
} | [
"public",
"function",
"removeOrphanPromotionFromSku",
"(",
"SKU",
"$",
"sku",
",",
"int",
"$",
"nid",
")",
"{",
"$",
"promotion_detach_item",
"[",
"]",
"=",
"[",
"'target_id'",
"=>",
"$",
"nid",
"]",
";",
"$",
"sku_promotions",
"=",
"$",
"sku",
"->",
"get",
"(",
"'field_acm_sku_promotions'",
")",
"->",
"getValue",
"(",
")",
";",
"$",
"sku_promotions",
"=",
"array_udiff",
"(",
"$",
"sku_promotions",
",",
"$",
"promotion_detach_item",
",",
"function",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"return",
"$",
"array1",
"[",
"'target_id'",
"]",
"-",
"$",
"array2",
"[",
"'target_id'",
"]",
";",
"}",
")",
";",
"$",
"sku",
"->",
"get",
"(",
"'field_acm_sku_promotions'",
")",
"->",
"setValue",
"(",
"$",
"sku_promotions",
")",
";",
"$",
"sku",
"->",
"save",
"(",
")",
";",
"// Update Sku Translations.",
"$",
"translation_languages",
"=",
"$",
"sku",
"->",
"getTranslationLanguages",
"(",
"TRUE",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"translation_languages",
")",
")",
"{",
"foreach",
"(",
"$",
"translation_languages",
"as",
"$",
"langcode",
"=>",
"$",
"language",
")",
"{",
"$",
"sku_entity_translation",
"=",
"$",
"sku",
"->",
"getTranslation",
"(",
"$",
"langcode",
")",
";",
"$",
"sku_entity_translation",
"->",
"get",
"(",
"'field_acm_sku_promotions'",
")",
"->",
"setValue",
"(",
"$",
"sku_promotions",
")",
";",
"$",
"sku_entity_translation",
"->",
"save",
"(",
")",
";",
"}",
"}",
"}"
]
| Removes the given promotion from SKU entity.
@param \Drupal\acm_sku\Entity\SKU $sku
SKU Entity.
@param int $nid
Promotion node id. | [
"Removes",
"the",
"given",
"promotion",
"from",
"SKU",
"entity",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/AcmPromotionsManager.php#L495-L512 | train |
acquia/commerce-manager | modules/acm_exception/src/EventSubscriber/RouteExceptionEventSubscriber.php | RouteExceptionEventSubscriber.onException | public function onException(RouteExceptionEvent $event) {
$exception = $event->getException();
$handler = \Drupal::service('acm_exception.route_exception_handler');
$handler->message($exception);
$handler->log($exception);
} | php | public function onException(RouteExceptionEvent $event) {
$exception = $event->getException();
$handler = \Drupal::service('acm_exception.route_exception_handler');
$handler->message($exception);
$handler->log($exception);
} | [
"public",
"function",
"onException",
"(",
"RouteExceptionEvent",
"$",
"event",
")",
"{",
"$",
"exception",
"=",
"$",
"event",
"->",
"getException",
"(",
")",
";",
"$",
"handler",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm_exception.route_exception_handler'",
")",
";",
"$",
"handler",
"->",
"message",
"(",
"$",
"exception",
")",
";",
"$",
"handler",
"->",
"log",
"(",
"$",
"exception",
")",
";",
"}"
]
| User messaging for RouteExceptions.
@param \Drupal\acm\RouteExceptionEvent $event
The event to process. | [
"User",
"messaging",
"for",
"RouteExceptions",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/EventSubscriber/RouteExceptionEventSubscriber.php#L19-L24 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Script/Notification/AbstractNotificationScript.php | AbstractNotificationScript.handleNotification | private function handleNotification(Notification $notification)
{
if (empty($notification->targetTypes())) {
return;
}
$objectsByTypes = [];
$numTotal = 0;
foreach ($notification->targetTypes() as $objType) {
$objType = trim($objType);
$objects = $this->updatedObjects($objType);
$num = count($objects);
if ($num == 0) {
continue;
}
$obj = [];
$obj['objects'] = $objects;
$obj['num'] = $num;
$obj['type'] = $objType;
$obj['typeLabel'] = isset($objects[0]['targetTypeLabel']) ? $objects[0]['targetTypeLabel'] : $objType;
$objectsByTypes[$objType] = $obj;
$numTotal += $num;
}
$this->sendEmail($notification, $objectsByTypes, $numTotal);
} | php | private function handleNotification(Notification $notification)
{
if (empty($notification->targetTypes())) {
return;
}
$objectsByTypes = [];
$numTotal = 0;
foreach ($notification->targetTypes() as $objType) {
$objType = trim($objType);
$objects = $this->updatedObjects($objType);
$num = count($objects);
if ($num == 0) {
continue;
}
$obj = [];
$obj['objects'] = $objects;
$obj['num'] = $num;
$obj['type'] = $objType;
$obj['typeLabel'] = isset($objects[0]['targetTypeLabel']) ? $objects[0]['targetTypeLabel'] : $objType;
$objectsByTypes[$objType] = $obj;
$numTotal += $num;
}
$this->sendEmail($notification, $objectsByTypes, $numTotal);
} | [
"private",
"function",
"handleNotification",
"(",
"Notification",
"$",
"notification",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"notification",
"->",
"targetTypes",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"objectsByTypes",
"=",
"[",
"]",
";",
"$",
"numTotal",
"=",
"0",
";",
"foreach",
"(",
"$",
"notification",
"->",
"targetTypes",
"(",
")",
"as",
"$",
"objType",
")",
"{",
"$",
"objType",
"=",
"trim",
"(",
"$",
"objType",
")",
";",
"$",
"objects",
"=",
"$",
"this",
"->",
"updatedObjects",
"(",
"$",
"objType",
")",
";",
"$",
"num",
"=",
"count",
"(",
"$",
"objects",
")",
";",
"if",
"(",
"$",
"num",
"==",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"obj",
"=",
"[",
"]",
";",
"$",
"obj",
"[",
"'objects'",
"]",
"=",
"$",
"objects",
";",
"$",
"obj",
"[",
"'num'",
"]",
"=",
"$",
"num",
";",
"$",
"obj",
"[",
"'type'",
"]",
"=",
"$",
"objType",
";",
"$",
"obj",
"[",
"'typeLabel'",
"]",
"=",
"isset",
"(",
"$",
"objects",
"[",
"0",
"]",
"[",
"'targetTypeLabel'",
"]",
")",
"?",
"$",
"objects",
"[",
"0",
"]",
"[",
"'targetTypeLabel'",
"]",
":",
"$",
"objType",
";",
"$",
"objectsByTypes",
"[",
"$",
"objType",
"]",
"=",
"$",
"obj",
";",
"$",
"numTotal",
"+=",
"$",
"num",
";",
"}",
"$",
"this",
"->",
"sendEmail",
"(",
"$",
"notification",
",",
"$",
"objectsByTypes",
",",
"$",
"numTotal",
")",
";",
"}"
]
| Handle a notification request
@param Notification $notification The notification object to handle.
@return void | [
"Handle",
"a",
"notification",
"request"
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Script/Notification/AbstractNotificationScript.php#L171-L195 | train |
acquia/commerce-manager | modules/acm_exception/src/EventSubscriber/RouteExceptionSubscriber.php | RouteExceptionSubscriber.onException | public function onException(GetResponseForExceptionEvent $event) {
$exception = $event->getException();
if (!($exception instanceof RouteException) || PHP_SAPI === 'cli') {
return;
}
$handler = \Drupal::service('acm_exception.route_exception_handler');
$redirect = $handler->getRedirect($exception);
$event->setResponse(RedirectResponse::create($redirect, 302));
} | php | public function onException(GetResponseForExceptionEvent $event) {
$exception = $event->getException();
if (!($exception instanceof RouteException) || PHP_SAPI === 'cli') {
return;
}
$handler = \Drupal::service('acm_exception.route_exception_handler');
$redirect = $handler->getRedirect($exception);
$event->setResponse(RedirectResponse::create($redirect, 302));
} | [
"public",
"function",
"onException",
"(",
"GetResponseForExceptionEvent",
"$",
"event",
")",
"{",
"$",
"exception",
"=",
"$",
"event",
"->",
"getException",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"exception",
"instanceof",
"RouteException",
")",
"||",
"PHP_SAPI",
"===",
"'cli'",
")",
"{",
"return",
";",
"}",
"$",
"handler",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm_exception.route_exception_handler'",
")",
";",
"$",
"redirect",
"=",
"$",
"handler",
"->",
"getRedirect",
"(",
"$",
"exception",
")",
";",
"$",
"event",
"->",
"setResponse",
"(",
"RedirectResponse",
"::",
"create",
"(",
"$",
"redirect",
",",
"302",
")",
")",
";",
"}"
]
| Catch all uncaught RouteException exceptions.
@param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
The event to process. | [
"Catch",
"all",
"uncaught",
"RouteException",
"exceptions",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/EventSubscriber/RouteExceptionSubscriber.php#L22-L31 | train |
acquia/commerce-manager | modules/acm_sku/src/ProductManager.php | ProductManager.updateNodeTranslation | public function updateNodeTranslation(NodeInterface &$node, array $product, string $langcode) {
$description = (isset($product['attributes']['description'])) ? $product['attributes']['description'] : '';
$categories = (isset($product['categories'])) ? $product['categories'] : [];
$config = $this->configFactory->get('acm.connector');
$sku_field_name = $config->get('sku_field_name') ?: 'field_skus';
$category_field_name = $config->get('category_field_name');
$text_format = $config->get('text_format') ?: 'rich_text';
$node_title = html_entity_decode($product['name']);
if ($config->get('product_title_use_sku')) {
$node_title = html_entity_decode($product['sku']);
}
$node->setTitle($node_title);
$body = [
'value' => $description,
'format' => $text_format,
];
$node->set('body', $body);
// Add categories if they're configured to be synced.
if ($category_field_name) {
$categories = $this->formatCategories($categories);
$node->{$category_field_name} = $categories;
}
$node->{$sku_field_name} = [$product['sku']];
if ($config->get('product_publish')) {
$node->setPublished();
}
else {
$node->setUnpublished();
}
// Invoke the alter hook to allow all modules to update the node.
$this->moduleHandler->alter('acm_sku_product_node_translation_update', $node, $product, $langcode);
} | php | public function updateNodeTranslation(NodeInterface &$node, array $product, string $langcode) {
$description = (isset($product['attributes']['description'])) ? $product['attributes']['description'] : '';
$categories = (isset($product['categories'])) ? $product['categories'] : [];
$config = $this->configFactory->get('acm.connector');
$sku_field_name = $config->get('sku_field_name') ?: 'field_skus';
$category_field_name = $config->get('category_field_name');
$text_format = $config->get('text_format') ?: 'rich_text';
$node_title = html_entity_decode($product['name']);
if ($config->get('product_title_use_sku')) {
$node_title = html_entity_decode($product['sku']);
}
$node->setTitle($node_title);
$body = [
'value' => $description,
'format' => $text_format,
];
$node->set('body', $body);
// Add categories if they're configured to be synced.
if ($category_field_name) {
$categories = $this->formatCategories($categories);
$node->{$category_field_name} = $categories;
}
$node->{$sku_field_name} = [$product['sku']];
if ($config->get('product_publish')) {
$node->setPublished();
}
else {
$node->setUnpublished();
}
// Invoke the alter hook to allow all modules to update the node.
$this->moduleHandler->alter('acm_sku_product_node_translation_update', $node, $product, $langcode);
} | [
"public",
"function",
"updateNodeTranslation",
"(",
"NodeInterface",
"&",
"$",
"node",
",",
"array",
"$",
"product",
",",
"string",
"$",
"langcode",
")",
"{",
"$",
"description",
"=",
"(",
"isset",
"(",
"$",
"product",
"[",
"'attributes'",
"]",
"[",
"'description'",
"]",
")",
")",
"?",
"$",
"product",
"[",
"'attributes'",
"]",
"[",
"'description'",
"]",
":",
"''",
";",
"$",
"categories",
"=",
"(",
"isset",
"(",
"$",
"product",
"[",
"'categories'",
"]",
")",
")",
"?",
"$",
"product",
"[",
"'categories'",
"]",
":",
"[",
"]",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"configFactory",
"->",
"get",
"(",
"'acm.connector'",
")",
";",
"$",
"sku_field_name",
"=",
"$",
"config",
"->",
"get",
"(",
"'sku_field_name'",
")",
"?",
":",
"'field_skus'",
";",
"$",
"category_field_name",
"=",
"$",
"config",
"->",
"get",
"(",
"'category_field_name'",
")",
";",
"$",
"text_format",
"=",
"$",
"config",
"->",
"get",
"(",
"'text_format'",
")",
"?",
":",
"'rich_text'",
";",
"$",
"node_title",
"=",
"html_entity_decode",
"(",
"$",
"product",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'product_title_use_sku'",
")",
")",
"{",
"$",
"node_title",
"=",
"html_entity_decode",
"(",
"$",
"product",
"[",
"'sku'",
"]",
")",
";",
"}",
"$",
"node",
"->",
"setTitle",
"(",
"$",
"node_title",
")",
";",
"$",
"body",
"=",
"[",
"'value'",
"=>",
"$",
"description",
",",
"'format'",
"=>",
"$",
"text_format",
",",
"]",
";",
"$",
"node",
"->",
"set",
"(",
"'body'",
",",
"$",
"body",
")",
";",
"// Add categories if they're configured to be synced.",
"if",
"(",
"$",
"category_field_name",
")",
"{",
"$",
"categories",
"=",
"$",
"this",
"->",
"formatCategories",
"(",
"$",
"categories",
")",
";",
"$",
"node",
"->",
"{",
"$",
"category_field_name",
"}",
"=",
"$",
"categories",
";",
"}",
"$",
"node",
"->",
"{",
"$",
"sku_field_name",
"}",
"=",
"[",
"$",
"product",
"[",
"'sku'",
"]",
"]",
";",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'product_publish'",
")",
")",
"{",
"$",
"node",
"->",
"setPublished",
"(",
")",
";",
"}",
"else",
"{",
"$",
"node",
"->",
"setUnpublished",
"(",
")",
";",
"}",
"// Invoke the alter hook to allow all modules to update the node.",
"$",
"this",
"->",
"moduleHandler",
"->",
"alter",
"(",
"'acm_sku_product_node_translation_update'",
",",
"$",
"node",
",",
"$",
"product",
",",
"$",
"langcode",
")",
";",
"}"
]
| Update node translation.
@param \Drupal\node\NodeInterface $node
Object of node we want to update with precreated translation.
@param array $product
Array with product values.
@param string $langcode
Langcode string. | [
"Update",
"node",
"translation",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductManager.php#L241-L278 | train |
acquia/commerce-manager | modules/acm_sku/src/ProductManager.php | ProductManager.updateLinkedSkus | private function updateLinkedSkus($type, SKU &$sku, array $linked) {
// Reset the upsell skus to null.
$sku->{$type}->setValue([]);
$fieldData = [];
foreach ($linked as $link) {
if ($link['type'] != $type) {
continue;
}
$fieldData[$link['position']] = $link['linked_sku'];
}
// If there is no upsell skus to link, we simply return from here.
if (empty($fieldData)) {
return;
}
// Sort them based on position.
ksort($fieldData);
// Update the index to sequential values so we can set in field.
$fieldData = array_values($fieldData);
foreach ($fieldData as $delta => $value) {
$sku->{$type}->set($delta, $value);
}
} | php | private function updateLinkedSkus($type, SKU &$sku, array $linked) {
// Reset the upsell skus to null.
$sku->{$type}->setValue([]);
$fieldData = [];
foreach ($linked as $link) {
if ($link['type'] != $type) {
continue;
}
$fieldData[$link['position']] = $link['linked_sku'];
}
// If there is no upsell skus to link, we simply return from here.
if (empty($fieldData)) {
return;
}
// Sort them based on position.
ksort($fieldData);
// Update the index to sequential values so we can set in field.
$fieldData = array_values($fieldData);
foreach ($fieldData as $delta => $value) {
$sku->{$type}->set($delta, $value);
}
} | [
"private",
"function",
"updateLinkedSkus",
"(",
"$",
"type",
",",
"SKU",
"&",
"$",
"sku",
",",
"array",
"$",
"linked",
")",
"{",
"// Reset the upsell skus to null.",
"$",
"sku",
"->",
"{",
"$",
"type",
"}",
"->",
"setValue",
"(",
"[",
"]",
")",
";",
"$",
"fieldData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"linked",
"as",
"$",
"link",
")",
"{",
"if",
"(",
"$",
"link",
"[",
"'type'",
"]",
"!=",
"$",
"type",
")",
"{",
"continue",
";",
"}",
"$",
"fieldData",
"[",
"$",
"link",
"[",
"'position'",
"]",
"]",
"=",
"$",
"link",
"[",
"'linked_sku'",
"]",
";",
"}",
"// If there is no upsell skus to link, we simply return from here.",
"if",
"(",
"empty",
"(",
"$",
"fieldData",
")",
")",
"{",
"return",
";",
"}",
"// Sort them based on position.",
"ksort",
"(",
"$",
"fieldData",
")",
";",
"// Update the index to sequential values so we can set in field.",
"$",
"fieldData",
"=",
"array_values",
"(",
"$",
"fieldData",
")",
";",
"foreach",
"(",
"$",
"fieldData",
"as",
"$",
"delta",
"=>",
"$",
"value",
")",
"{",
"$",
"sku",
"->",
"{",
"$",
"type",
"}",
"->",
"set",
"(",
"$",
"delta",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Update linked Skus.
Prepare the field value for linked type (upsell, crosssell, etc.).
Get the position based on the position coming from API.
@param string $type
Type of link.
@param \Drupal\acm_sku\Entity\SKU $sku
Root SKU.
@param array $linked
Linked SKUs.
@throws \Drupal\Core\TypedData\Exception\ReadOnlyException
If the data is read-only.
@throws \Drupal\Core\TypedData\Exception\MissingDataException
If the complex data structure is unset and no item can be set. | [
"Update",
"linked",
"Skus",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductManager.php#L804-L825 | train |
acquia/commerce-manager | modules/acm_sku/src/ProductManager.php | ProductManager.updateFields | private function updateFields($parent, SKU $sku, array $values) {
$additionalFields = $this->skuFieldsManager->getFieldAdditions();
// Filter fields for the parent requested.
$additionalFields = array_filter($additionalFields, function ($field) use ($parent) {
return ($field['parent'] == $parent);
});
// Loop through all the fields we want to read from product data.
foreach ($additionalFields as $key => $field) {
$source = isset($field['source']) ? $field['source'] : $key;
// Field key.
$field_key = 'attr_' . $key;
switch ($field['type']) {
case 'attribute':
// If attribute is not coming in response, then unset it.
if (!isset($values[$source])) {
$sku->{$field_key}->set(0, NULL);
}
else {
$value = $values[$source];
$value = $field['cardinality'] != 1 ? explode(',', $value) : [$value];
foreach ($value as $index => $val) {
if ($term = $this->productOptionsManager->loadProductOptionByOptionId($source, $val, $sku->language()->getId())) {
$sku->{$field_key}->set($index, $term->getName());
}
else {
$sku->{$field_key}->set($index, $val);
}
}
}
break;
case 'string':
// If attribute is not coming in response, then unset it.
if (!isset($values[$source])) {
$sku->{$field_key}->setValue(NULL);
}
else {
$value = $values[$source];
$value = $field['cardinality'] != 1 ? explode(',', $value) : $value;
$sku->{$field_key}->setValue($value);
}
break;
case 'text_long':
// If attribute is not coming in response, then unset it.
if (!isset($values[$source])) {
$sku->{$field_key}->setValue(NULL);
}
else {
$value = $values[$source];
$value = !empty($field['serialize']) ? serialize($value) : $value;
$sku->{$field_key}->setValue($value);
}
break;
}
}
} | php | private function updateFields($parent, SKU $sku, array $values) {
$additionalFields = $this->skuFieldsManager->getFieldAdditions();
// Filter fields for the parent requested.
$additionalFields = array_filter($additionalFields, function ($field) use ($parent) {
return ($field['parent'] == $parent);
});
// Loop through all the fields we want to read from product data.
foreach ($additionalFields as $key => $field) {
$source = isset($field['source']) ? $field['source'] : $key;
// Field key.
$field_key = 'attr_' . $key;
switch ($field['type']) {
case 'attribute':
// If attribute is not coming in response, then unset it.
if (!isset($values[$source])) {
$sku->{$field_key}->set(0, NULL);
}
else {
$value = $values[$source];
$value = $field['cardinality'] != 1 ? explode(',', $value) : [$value];
foreach ($value as $index => $val) {
if ($term = $this->productOptionsManager->loadProductOptionByOptionId($source, $val, $sku->language()->getId())) {
$sku->{$field_key}->set($index, $term->getName());
}
else {
$sku->{$field_key}->set($index, $val);
}
}
}
break;
case 'string':
// If attribute is not coming in response, then unset it.
if (!isset($values[$source])) {
$sku->{$field_key}->setValue(NULL);
}
else {
$value = $values[$source];
$value = $field['cardinality'] != 1 ? explode(',', $value) : $value;
$sku->{$field_key}->setValue($value);
}
break;
case 'text_long':
// If attribute is not coming in response, then unset it.
if (!isset($values[$source])) {
$sku->{$field_key}->setValue(NULL);
}
else {
$value = $values[$source];
$value = !empty($field['serialize']) ? serialize($value) : $value;
$sku->{$field_key}->setValue($value);
}
break;
}
}
} | [
"private",
"function",
"updateFields",
"(",
"$",
"parent",
",",
"SKU",
"$",
"sku",
",",
"array",
"$",
"values",
")",
"{",
"$",
"additionalFields",
"=",
"$",
"this",
"->",
"skuFieldsManager",
"->",
"getFieldAdditions",
"(",
")",
";",
"// Filter fields for the parent requested.",
"$",
"additionalFields",
"=",
"array_filter",
"(",
"$",
"additionalFields",
",",
"function",
"(",
"$",
"field",
")",
"use",
"(",
"$",
"parent",
")",
"{",
"return",
"(",
"$",
"field",
"[",
"'parent'",
"]",
"==",
"$",
"parent",
")",
";",
"}",
")",
";",
"// Loop through all the fields we want to read from product data.",
"foreach",
"(",
"$",
"additionalFields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"$",
"source",
"=",
"isset",
"(",
"$",
"field",
"[",
"'source'",
"]",
")",
"?",
"$",
"field",
"[",
"'source'",
"]",
":",
"$",
"key",
";",
"// Field key.",
"$",
"field_key",
"=",
"'attr_'",
".",
"$",
"key",
";",
"switch",
"(",
"$",
"field",
"[",
"'type'",
"]",
")",
"{",
"case",
"'attribute'",
":",
"// If attribute is not coming in response, then unset it.",
"if",
"(",
"!",
"isset",
"(",
"$",
"values",
"[",
"$",
"source",
"]",
")",
")",
"{",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"set",
"(",
"0",
",",
"NULL",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"values",
"[",
"$",
"source",
"]",
";",
"$",
"value",
"=",
"$",
"field",
"[",
"'cardinality'",
"]",
"!=",
"1",
"?",
"explode",
"(",
"','",
",",
"$",
"value",
")",
":",
"[",
"$",
"value",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"index",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"term",
"=",
"$",
"this",
"->",
"productOptionsManager",
"->",
"loadProductOptionByOptionId",
"(",
"$",
"source",
",",
"$",
"val",
",",
"$",
"sku",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
"{",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"set",
"(",
"$",
"index",
",",
"$",
"term",
"->",
"getName",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"set",
"(",
"$",
"index",
",",
"$",
"val",
")",
";",
"}",
"}",
"}",
"break",
";",
"case",
"'string'",
":",
"// If attribute is not coming in response, then unset it.",
"if",
"(",
"!",
"isset",
"(",
"$",
"values",
"[",
"$",
"source",
"]",
")",
")",
"{",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"setValue",
"(",
"NULL",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"values",
"[",
"$",
"source",
"]",
";",
"$",
"value",
"=",
"$",
"field",
"[",
"'cardinality'",
"]",
"!=",
"1",
"?",
"explode",
"(",
"','",
",",
"$",
"value",
")",
":",
"$",
"value",
";",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}",
"break",
";",
"case",
"'text_long'",
":",
"// If attribute is not coming in response, then unset it.",
"if",
"(",
"!",
"isset",
"(",
"$",
"values",
"[",
"$",
"source",
"]",
")",
")",
"{",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"setValue",
"(",
"NULL",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"values",
"[",
"$",
"source",
"]",
";",
"$",
"value",
"=",
"!",
"empty",
"(",
"$",
"field",
"[",
"'serialize'",
"]",
")",
"?",
"serialize",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"$",
"sku",
"->",
"{",
"$",
"field_key",
"}",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}",
"break",
";",
"}",
"}",
"}"
]
| Update attribute fields.
Update the fields based on the values from attributes.
@param string $parent
Fields to get from this parent will be processed.
@param \Drupal\acm_sku\Entity\SKU $sku
The root SKU.
@param array $values
The product attributes/extensions to get value from.
@throws \Drupal\Core\TypedData\Exception\ReadOnlyException
If the data is read-only.
@throws \Drupal\Core\TypedData\Exception\MissingDataException
If the complex data structure is unset and no item can be set. | [
"Update",
"attribute",
"fields",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductManager.php#L844-L904 | train |
acquia/commerce-manager | modules/acm_sku/src/ProductManager.php | ProductManager.getProcessedMedia | protected function getProcessedMedia(array $product, $current_value) {
$media = [];
// The Commerce Connector Service sends the media information
// in $product['extension']['media'][0].
// We note $product['extension']['media'][1] is deliberately always empty.
// See Magento module method...
// Model/ProductSyncManagement::processMediaGalleryExtension()
// TODO What does Hybris send? The connector doesn't normalize.
if (isset(
$product['extension'],
$product['extension']['media'],
$product['extension']['media'][0])) {
// Conveniently reset() returns the first element of the array.
$media = reset($product['extension']['media']);
if (isset($product['attributes'], $product['attributes']['image'])) {
$image = $product['attributes']['image'];
// If the base image is in the gallery then position it first.
// But why? Is this an Acquia Commerce Manager requirement?
// It is normal in Magento to set a gallery position for the base image
// And to set images as 'hide in gallery' ie ['disabled'] = 1
// So I suggest we honor the Magento data here.
// TODO What does Hybris send? (what would the normalization be?)
// Maybe we just bring in all images and let the Drupal user decide
// what to display and in which position.
// Later, will the Drupal theme honor ['disabled'] = 1 or do we
// need to omit ['disabled'] = 1 images here.
foreach ($media as &$data) {
if (substr_compare($data['file'], $image, -strlen($image)) === 0) {
$data['position'] = -1;
break;
}
}
}
// Sort media data by position. Noting disabled images are included.
usort($media, function ($a, $b) {
$position1 = (int) $a['position'];
$position2 = (int) $b['position'];
if ($position1 == $position2) {
return 0;
}
return ($position1 < $position2) ? -1 : 1;
});
}
// Reassign old files to not have to redownload them.
if (!empty($media)) {
$current_media = unserialize($current_value);
if (!empty($current_media) && is_array($current_media)) {
$current_mapping = [];
foreach ($current_media as $value) {
if (!empty($value['fid'])) {
$current_mapping[$value['value_id']]['fid'] = $value['fid'];
$current_mapping[$value['value_id']]['file'] = $value['file'];
}
}
foreach ($media as $key => $value) {
if (isset($current_mapping[$value['value_id']])) {
$media[$key]['fid'] = $current_mapping[$value['value_id']]['fid'];
$media[$key]['file'] = $current_mapping[$value['value_id']]['file'];
}
}
}
}
return serialize($media);
} | php | protected function getProcessedMedia(array $product, $current_value) {
$media = [];
// The Commerce Connector Service sends the media information
// in $product['extension']['media'][0].
// We note $product['extension']['media'][1] is deliberately always empty.
// See Magento module method...
// Model/ProductSyncManagement::processMediaGalleryExtension()
// TODO What does Hybris send? The connector doesn't normalize.
if (isset(
$product['extension'],
$product['extension']['media'],
$product['extension']['media'][0])) {
// Conveniently reset() returns the first element of the array.
$media = reset($product['extension']['media']);
if (isset($product['attributes'], $product['attributes']['image'])) {
$image = $product['attributes']['image'];
// If the base image is in the gallery then position it first.
// But why? Is this an Acquia Commerce Manager requirement?
// It is normal in Magento to set a gallery position for the base image
// And to set images as 'hide in gallery' ie ['disabled'] = 1
// So I suggest we honor the Magento data here.
// TODO What does Hybris send? (what would the normalization be?)
// Maybe we just bring in all images and let the Drupal user decide
// what to display and in which position.
// Later, will the Drupal theme honor ['disabled'] = 1 or do we
// need to omit ['disabled'] = 1 images here.
foreach ($media as &$data) {
if (substr_compare($data['file'], $image, -strlen($image)) === 0) {
$data['position'] = -1;
break;
}
}
}
// Sort media data by position. Noting disabled images are included.
usort($media, function ($a, $b) {
$position1 = (int) $a['position'];
$position2 = (int) $b['position'];
if ($position1 == $position2) {
return 0;
}
return ($position1 < $position2) ? -1 : 1;
});
}
// Reassign old files to not have to redownload them.
if (!empty($media)) {
$current_media = unserialize($current_value);
if (!empty($current_media) && is_array($current_media)) {
$current_mapping = [];
foreach ($current_media as $value) {
if (!empty($value['fid'])) {
$current_mapping[$value['value_id']]['fid'] = $value['fid'];
$current_mapping[$value['value_id']]['file'] = $value['file'];
}
}
foreach ($media as $key => $value) {
if (isset($current_mapping[$value['value_id']])) {
$media[$key]['fid'] = $current_mapping[$value['value_id']]['fid'];
$media[$key]['file'] = $current_mapping[$value['value_id']]['file'];
}
}
}
}
return serialize($media);
} | [
"protected",
"function",
"getProcessedMedia",
"(",
"array",
"$",
"product",
",",
"$",
"current_value",
")",
"{",
"$",
"media",
"=",
"[",
"]",
";",
"// The Commerce Connector Service sends the media information",
"// in $product['extension']['media'][0].",
"// We note $product['extension']['media'][1] is deliberately always empty.",
"// See Magento module method...",
"// Model/ProductSyncManagement::processMediaGalleryExtension()",
"// TODO What does Hybris send? The connector doesn't normalize.",
"if",
"(",
"isset",
"(",
"$",
"product",
"[",
"'extension'",
"]",
",",
"$",
"product",
"[",
"'extension'",
"]",
"[",
"'media'",
"]",
",",
"$",
"product",
"[",
"'extension'",
"]",
"[",
"'media'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"// Conveniently reset() returns the first element of the array.",
"$",
"media",
"=",
"reset",
"(",
"$",
"product",
"[",
"'extension'",
"]",
"[",
"'media'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"product",
"[",
"'attributes'",
"]",
",",
"$",
"product",
"[",
"'attributes'",
"]",
"[",
"'image'",
"]",
")",
")",
"{",
"$",
"image",
"=",
"$",
"product",
"[",
"'attributes'",
"]",
"[",
"'image'",
"]",
";",
"// If the base image is in the gallery then position it first.",
"// But why? Is this an Acquia Commerce Manager requirement?",
"// It is normal in Magento to set a gallery position for the base image",
"// And to set images as 'hide in gallery' ie ['disabled'] = 1",
"// So I suggest we honor the Magento data here.",
"// TODO What does Hybris send? (what would the normalization be?)",
"// Maybe we just bring in all images and let the Drupal user decide",
"// what to display and in which position.",
"// Later, will the Drupal theme honor ['disabled'] = 1 or do we",
"// need to omit ['disabled'] = 1 images here.",
"foreach",
"(",
"$",
"media",
"as",
"&",
"$",
"data",
")",
"{",
"if",
"(",
"substr_compare",
"(",
"$",
"data",
"[",
"'file'",
"]",
",",
"$",
"image",
",",
"-",
"strlen",
"(",
"$",
"image",
")",
")",
"===",
"0",
")",
"{",
"$",
"data",
"[",
"'position'",
"]",
"=",
"-",
"1",
";",
"break",
";",
"}",
"}",
"}",
"// Sort media data by position. Noting disabled images are included.",
"usort",
"(",
"$",
"media",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"position1",
"=",
"(",
"int",
")",
"$",
"a",
"[",
"'position'",
"]",
";",
"$",
"position2",
"=",
"(",
"int",
")",
"$",
"b",
"[",
"'position'",
"]",
";",
"if",
"(",
"$",
"position1",
"==",
"$",
"position2",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"position1",
"<",
"$",
"position2",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"}",
"// Reassign old files to not have to redownload them.",
"if",
"(",
"!",
"empty",
"(",
"$",
"media",
")",
")",
"{",
"$",
"current_media",
"=",
"unserialize",
"(",
"$",
"current_value",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"current_media",
")",
"&&",
"is_array",
"(",
"$",
"current_media",
")",
")",
"{",
"$",
"current_mapping",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"current_media",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
"[",
"'fid'",
"]",
")",
")",
"{",
"$",
"current_mapping",
"[",
"$",
"value",
"[",
"'value_id'",
"]",
"]",
"[",
"'fid'",
"]",
"=",
"$",
"value",
"[",
"'fid'",
"]",
";",
"$",
"current_mapping",
"[",
"$",
"value",
"[",
"'value_id'",
"]",
"]",
"[",
"'file'",
"]",
"=",
"$",
"value",
"[",
"'file'",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"media",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"current_mapping",
"[",
"$",
"value",
"[",
"'value_id'",
"]",
"]",
")",
")",
"{",
"$",
"media",
"[",
"$",
"key",
"]",
"[",
"'fid'",
"]",
"=",
"$",
"current_mapping",
"[",
"$",
"value",
"[",
"'value_id'",
"]",
"]",
"[",
"'fid'",
"]",
";",
"$",
"media",
"[",
"$",
"key",
"]",
"[",
"'file'",
"]",
"=",
"$",
"current_mapping",
"[",
"$",
"value",
"[",
"'value_id'",
"]",
"]",
"[",
"'file'",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"serialize",
"(",
"$",
"media",
")",
";",
"}"
]
| Extracts and orders the media gallery by position and sets the main image.
Extracts the media gallery fields from product[extension][media][0].
Orders the media gallery by position and sets the base (main) image
to be positioned first.
Disabled images are left in place.
@param array $product
Array with product information.
@param string $current_value
The current media data of the sku bein processed.
@return string
Serialized array with product's media information. | [
"Extracts",
"and",
"orders",
"the",
"media",
"gallery",
"by",
"position",
"and",
"sets",
"the",
"main",
"image",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductManager.php#L922-L995 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/HierarchicalObjectProperty.php | HierarchicalObjectProperty.choices | public function choices()
{
$choices = [];
$proto = $this->proto();
if (!$proto->source()->tableExists()) {
return $choices;
}
$loader = $this->collectionModelLoader();
$collection = new HierarchicalCollection($loader->load(), false);
$collection->setPage($loader->page())
->setNumPerPage($loader->numPerPage())
->sortTree();
return $this->parseChoices($collection);
} | php | public function choices()
{
$choices = [];
$proto = $this->proto();
if (!$proto->source()->tableExists()) {
return $choices;
}
$loader = $this->collectionModelLoader();
$collection = new HierarchicalCollection($loader->load(), false);
$collection->setPage($loader->page())
->setNumPerPage($loader->numPerPage())
->sortTree();
return $this->parseChoices($collection);
} | [
"public",
"function",
"choices",
"(",
")",
"{",
"$",
"choices",
"=",
"[",
"]",
";",
"$",
"proto",
"=",
"$",
"this",
"->",
"proto",
"(",
")",
";",
"if",
"(",
"!",
"$",
"proto",
"->",
"source",
"(",
")",
"->",
"tableExists",
"(",
")",
")",
"{",
"return",
"$",
"choices",
";",
"}",
"$",
"loader",
"=",
"$",
"this",
"->",
"collectionModelLoader",
"(",
")",
";",
"$",
"collection",
"=",
"new",
"HierarchicalCollection",
"(",
"$",
"loader",
"->",
"load",
"(",
")",
",",
"false",
")",
";",
"$",
"collection",
"->",
"setPage",
"(",
"$",
"loader",
"->",
"page",
"(",
")",
")",
"->",
"setNumPerPage",
"(",
"$",
"loader",
"->",
"numPerPage",
"(",
")",
")",
"->",
"sortTree",
"(",
")",
";",
"return",
"$",
"this",
"->",
"parseChoices",
"(",
"$",
"collection",
")",
";",
"}"
]
| Retrieve the available choice structures, segmented as a tree.
@return array | [
"Retrieve",
"the",
"available",
"choice",
"structures",
"segmented",
"as",
"a",
"tree",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/HierarchicalObjectProperty.php#L37-L54 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/FeedbackContainerTrait.php | FeedbackContainerTrait.feedbacks | public function feedbacks($level = null)
{
if ($level !== null) {
if (!is_string($level)) {
throw new InvalidArgumentException('The feedback level must be a string');
}
$level = $this->resolveFeedbackLevel($level);
$subset = [];
foreach ($this->feedbacks as $item) {
if ($item['level'] === $level) {
$subset[] = $item;
}
}
return $subset;
}
return $this->feedbacks;
} | php | public function feedbacks($level = null)
{
if ($level !== null) {
if (!is_string($level)) {
throw new InvalidArgumentException('The feedback level must be a string');
}
$level = $this->resolveFeedbackLevel($level);
$subset = [];
foreach ($this->feedbacks as $item) {
if ($item['level'] === $level) {
$subset[] = $item;
}
}
return $subset;
}
return $this->feedbacks;
} | [
"public",
"function",
"feedbacks",
"(",
"$",
"level",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"level",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"level",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The feedback level must be a string'",
")",
";",
"}",
"$",
"level",
"=",
"$",
"this",
"->",
"resolveFeedbackLevel",
"(",
"$",
"level",
")",
";",
"$",
"subset",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"feedbacks",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'level'",
"]",
"===",
"$",
"level",
")",
"{",
"$",
"subset",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"subset",
";",
"}",
"return",
"$",
"this",
"->",
"feedbacks",
";",
"}"
]
| Retrieve the feedback collection.
Optionally retrieve only the feedback for the given level.
@param string|null $level Optional level to filter collection.
@throws InvalidArgumentException If the feedback level is invalid.
@return array | [
"Retrieve",
"the",
"feedback",
"collection",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/FeedbackContainerTrait.php#L49-L69 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/FeedbackContainerTrait.php | FeedbackContainerTrait.parseFeedback | final protected function parseFeedback(array $entry)
{
$fid = $this->generateFeedbackEntryId();
$entry['id'] = $fid;
$entry = $this->parseFeedbackEntry($entry);
if (empty($entry['id']) || $entry['id'] !== $fid) {
throw new UnexpectedValueException('The unique ID assigned to the feedback must not be changed.');
}
if (empty($entry['level']) || empty($entry['message'])) {
throw new InvalidArgumentException('Feedback requires a "level" and a "message".');
}
$entry['type'] = $this->resolveFeedbackType($entry['level']);
$entry['level'] = $this->resolveFeedbackLevel($entry['level']);
return $entry;
} | php | final protected function parseFeedback(array $entry)
{
$fid = $this->generateFeedbackEntryId();
$entry['id'] = $fid;
$entry = $this->parseFeedbackEntry($entry);
if (empty($entry['id']) || $entry['id'] !== $fid) {
throw new UnexpectedValueException('The unique ID assigned to the feedback must not be changed.');
}
if (empty($entry['level']) || empty($entry['message'])) {
throw new InvalidArgumentException('Feedback requires a "level" and a "message".');
}
$entry['type'] = $this->resolveFeedbackType($entry['level']);
$entry['level'] = $this->resolveFeedbackLevel($entry['level']);
return $entry;
} | [
"final",
"protected",
"function",
"parseFeedback",
"(",
"array",
"$",
"entry",
")",
"{",
"$",
"fid",
"=",
"$",
"this",
"->",
"generateFeedbackEntryId",
"(",
")",
";",
"$",
"entry",
"[",
"'id'",
"]",
"=",
"$",
"fid",
";",
"$",
"entry",
"=",
"$",
"this",
"->",
"parseFeedbackEntry",
"(",
"$",
"entry",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"entry",
"[",
"'id'",
"]",
")",
"||",
"$",
"entry",
"[",
"'id'",
"]",
"!==",
"$",
"fid",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'The unique ID assigned to the feedback must not be changed.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"entry",
"[",
"'level'",
"]",
")",
"||",
"empty",
"(",
"$",
"entry",
"[",
"'message'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Feedback requires a \"level\" and a \"message\".'",
")",
";",
"}",
"$",
"entry",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"resolveFeedbackType",
"(",
"$",
"entry",
"[",
"'level'",
"]",
")",
";",
"$",
"entry",
"[",
"'level'",
"]",
"=",
"$",
"this",
"->",
"resolveFeedbackLevel",
"(",
"$",
"entry",
"[",
"'level'",
"]",
")",
";",
"return",
"$",
"entry",
";",
"}"
]
| Parse a feedback entry.
@param array $entry A dataset describing the feedback entry.
@throws InvalidArgumentException If the feedback entry is invalid.
@throws UnexpectedValueException If the feedback entry ID was altered.
@return array A parsed feedback entry. | [
"Parse",
"a",
"feedback",
"entry",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/FeedbackContainerTrait.php#L107-L126 | train |
acquia/commerce-manager | modules/acm_exception/src/RouteExceptionHandler.php | RouteExceptionHandler.message | public function message(RouteException $e) {
$message = $this->getConfig('message', $e);
if (!empty($message) && PHP_SAPI !== 'cli') {
drupal_set_message($message, 'error');
}
} | php | public function message(RouteException $e) {
$message = $this->getConfig('message', $e);
if (!empty($message) && PHP_SAPI !== 'cli') {
drupal_set_message($message, 'error');
}
} | [
"public",
"function",
"message",
"(",
"RouteException",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'message'",
",",
"$",
"e",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"message",
")",
"&&",
"PHP_SAPI",
"!==",
"'cli'",
")",
"{",
"drupal_set_message",
"(",
"$",
"message",
",",
"'error'",
")",
";",
"}",
"}"
]
| Present the error message for this RouteException to the user.
@param \Drupal\acm\Connector\RouteException $e
The RouteException that was thrown. | [
"Present",
"the",
"error",
"message",
"for",
"this",
"RouteException",
"to",
"the",
"user",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/RouteExceptionHandler.php#L48-L53 | train |
acquia/commerce-manager | modules/acm_exception/src/RouteExceptionHandler.php | RouteExceptionHandler.log | public function log(RouteException $e) {
if (empty($this->getConfig('log', $e))) {
return;
}
$this->logger->critical("Exception thrown during the {$e->getOperation()} operation.<br /><strong>Response code:</strong> {$e->getCode()}<br /><strong>Response body:</strong><pre>{$e->getMessage()}</pre>");
} | php | public function log(RouteException $e) {
if (empty($this->getConfig('log', $e))) {
return;
}
$this->logger->critical("Exception thrown during the {$e->getOperation()} operation.<br /><strong>Response code:</strong> {$e->getCode()}<br /><strong>Response body:</strong><pre>{$e->getMessage()}</pre>");
} | [
"public",
"function",
"log",
"(",
"RouteException",
"$",
"e",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'log'",
",",
"$",
"e",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"\"Exception thrown during the {$e->getOperation()} operation.<br /><strong>Response code:</strong> {$e->getCode()}<br /><strong>Response body:</strong><pre>{$e->getMessage()}</pre>\"",
")",
";",
"}"
]
| Generate a log message.
@param \Drupal\acm\Connector\RouteException $e
The RouteException that was thrown. | [
"Generate",
"a",
"log",
"message",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/RouteExceptionHandler.php#L61-L67 | train |
acquia/commerce-manager | modules/acm_exception/src/RouteExceptionHandler.php | RouteExceptionHandler.getRedirect | public function getRedirect(RouteException $e) {
$redirect = $this->getConfig('redirect', $e);
if (empty($redirect)) {
$redirect = '<current>';
}
return Url::fromUri("internal:/{$redirect}")->toString();
} | php | public function getRedirect(RouteException $e) {
$redirect = $this->getConfig('redirect', $e);
if (empty($redirect)) {
$redirect = '<current>';
}
return Url::fromUri("internal:/{$redirect}")->toString();
} | [
"public",
"function",
"getRedirect",
"(",
"RouteException",
"$",
"e",
")",
"{",
"$",
"redirect",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'redirect'",
",",
"$",
"e",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"redirect",
")",
")",
"{",
"$",
"redirect",
"=",
"'<current>'",
";",
"}",
"return",
"Url",
"::",
"fromUri",
"(",
"\"internal:/{$redirect}\"",
")",
"->",
"toString",
"(",
")",
";",
"}"
]
| Get the exception redirect from storage.
@param \Drupal\acm\Connector\RouteException $e
The RouteException that was thrown.
@return string
The redirect to perform. | [
"Get",
"the",
"exception",
"redirect",
"from",
"storage",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/RouteExceptionHandler.php#L78-L84 | train |
acquia/commerce-manager | modules/acm_exception/src/RouteExceptionHandler.php | RouteExceptionHandler.getConfig | private function getConfig($key, RouteException $e) {
$scenario = $e->getOperation();
$default = $this->config->get("default.{$key}");
$scenario = $this->config->get("routes.{$scenario}.{$key}");
foreach ([$scenario, $default] as $candidate) {
if (!empty(trim($candidate))) {
return $candidate;
}
}
return NULL;
} | php | private function getConfig($key, RouteException $e) {
$scenario = $e->getOperation();
$default = $this->config->get("default.{$key}");
$scenario = $this->config->get("routes.{$scenario}.{$key}");
foreach ([$scenario, $default] as $candidate) {
if (!empty(trim($candidate))) {
return $candidate;
}
}
return NULL;
} | [
"private",
"function",
"getConfig",
"(",
"$",
"key",
",",
"RouteException",
"$",
"e",
")",
"{",
"$",
"scenario",
"=",
"$",
"e",
"->",
"getOperation",
"(",
")",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"\"default.{$key}\"",
")",
";",
"$",
"scenario",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"\"routes.{$scenario}.{$key}\"",
")",
";",
"foreach",
"(",
"[",
"$",
"scenario",
",",
"$",
"default",
"]",
"as",
"$",
"candidate",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"trim",
"(",
"$",
"candidate",
")",
")",
")",
"{",
"return",
"$",
"candidate",
";",
"}",
"}",
"return",
"NULL",
";",
"}"
]
| Fetch config for a given RouteException.
Looks for scenario specific config and then falls back on defaults.
@param string $key
The exception config key to fetch.
@param \Drupal\acm\Connector\RouteException $e
The RouteException that was thrown.
@return mixed
The config on success. | [
"Fetch",
"config",
"for",
"a",
"given",
"RouteException",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/RouteExceptionHandler.php#L99-L109 | train |
acquia/commerce-manager | modules/acm/src/Element/AcmTitleSelect.php | AcmTitleSelect.processAcmTitleSelect | public static function processAcmTitleSelect(array $element) {
$element['#options'] = [
'Mr' => t('Mr'),
'Mrs' => t('Mrs'),
'Ms' => t('Ms'),
'Miss' => t('Miss'),
'Dr' => t('Dr'),
'Prof.' => t('Prof.'),
'Brigadier' => t('Brigadier'),
'Reverend' => t('Reverend'),
];
return $element;
} | php | public static function processAcmTitleSelect(array $element) {
$element['#options'] = [
'Mr' => t('Mr'),
'Mrs' => t('Mrs'),
'Ms' => t('Ms'),
'Miss' => t('Miss'),
'Dr' => t('Dr'),
'Prof.' => t('Prof.'),
'Brigadier' => t('Brigadier'),
'Reverend' => t('Reverend'),
];
return $element;
} | [
"public",
"static",
"function",
"processAcmTitleSelect",
"(",
"array",
"$",
"element",
")",
"{",
"$",
"element",
"[",
"'#options'",
"]",
"=",
"[",
"'Mr'",
"=>",
"t",
"(",
"'Mr'",
")",
",",
"'Mrs'",
"=>",
"t",
"(",
"'Mrs'",
")",
",",
"'Ms'",
"=>",
"t",
"(",
"'Ms'",
")",
",",
"'Miss'",
"=>",
"t",
"(",
"'Miss'",
")",
",",
"'Dr'",
"=>",
"t",
"(",
"'Dr'",
")",
",",
"'Prof.'",
"=>",
"t",
"(",
"'Prof.'",
")",
",",
"'Brigadier'",
"=>",
"t",
"(",
"'Brigadier'",
")",
",",
"'Reverend'",
"=>",
"t",
"(",
"'Reverend'",
")",
",",
"]",
";",
"return",
"$",
"element",
";",
"}"
]
| Adds in an option list of applicable titles.
@param array $element
An associative array containing the properties of the element.
Properties used: #title, #value, #options, #description, #required,
#attributes, #id, #name, #type, #min, #max, #step, #value, #size. The
#name property will be sanitized before output. This is currently done by
initializing Drupal\Core\Template\Attribute with all the attributes.
@return array
The $element with prepared variables. | [
"Adds",
"in",
"an",
"option",
"list",
"of",
"applicable",
"titles",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Element/AcmTitleSelect.php#L38-L50 | train |
yzalis/SupervisorBundle | Manager/SupervisorManager.php | SupervisorManager.getSupervisorByKey | public function getSupervisorByKey($key)
{
if (isset($this->supervisors[$key])) {
return $this->supervisors[$key];
}
return null;
} | php | public function getSupervisorByKey($key)
{
if (isset($this->supervisors[$key])) {
return $this->supervisors[$key];
}
return null;
} | [
"public",
"function",
"getSupervisorByKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"supervisors",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"supervisors",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Get Supervisor by key
@param string $key
@return Supervisor|null | [
"Get",
"Supervisor",
"by",
"key"
]
| 0b3fae253246fe861d0223a3ddbb37a5465eae6f | https://github.com/yzalis/SupervisorBundle/blob/0b3fae253246fe861d0223a3ddbb37a5465eae6f/Manager/SupervisorManager.php#L52-L59 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.configurableAjaxCallback | public static function configurableAjaxCallback(array $form, FormStateInterface $form_state) {
$dynamic_parts = &$form['ajax'];
$configurables = $form_state->getValue('configurables');
/** @var \Drupal\acm_sku\CartFormHelper $helper */
$helper = \Drupal::service('acm_sku.cart_form_helper');
$tree = $form_state->get('tree');
$tree_pointer = &$tree['options'];
foreach ($configurables as $key => $value) {
if (empty($value)) {
continue;
}
// Move the tree pointer if the selection is valid.
if (isset($tree_pointer["$key:$value"])) {
$tree_pointer = &$tree_pointer["$key:$value"];
}
}
if ($tree_pointer instanceof SKU) {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('acm_sku');
$view = $view_builder->view($tree_pointer);
// Block add to cart render because Form API won't allow AJAX Formception.
$view['#no_add_to_cart'] = TRUE;
$dynamic_parts['add_to_cart'] = [
'entity_render' => ['#markup' => render($view)],
];
}
else {
$available_config = $tree_pointer['#available_config'];
foreach ($available_config as $key => $config) {
$options = [
'' => $dynamic_parts['configurables']['color']['#options'][''],
];
foreach ($config['values'] as $value) {
$options[$value['value_id']] = $value['label'];
}
// Sort config options before pushing them to the select list based on
// the config.
if ($helper->isAttributeSortable($key)) {
// Make sure the first element in the list is the empty option.
$sorted_options = [
'' => $dynamic_parts['configurables'][$key]['#options'][''],
];
$sorted_options += self::sortConfigOptions($options, $key);
}
else {
// Use this in case the attribute is not sortable as per the config.
$sorted_options = $options;
}
$dynamic_parts['configurables'][$key]['#options'] = $sorted_options;
}
}
return $dynamic_parts;
} | php | public static function configurableAjaxCallback(array $form, FormStateInterface $form_state) {
$dynamic_parts = &$form['ajax'];
$configurables = $form_state->getValue('configurables');
/** @var \Drupal\acm_sku\CartFormHelper $helper */
$helper = \Drupal::service('acm_sku.cart_form_helper');
$tree = $form_state->get('tree');
$tree_pointer = &$tree['options'];
foreach ($configurables as $key => $value) {
if (empty($value)) {
continue;
}
// Move the tree pointer if the selection is valid.
if (isset($tree_pointer["$key:$value"])) {
$tree_pointer = &$tree_pointer["$key:$value"];
}
}
if ($tree_pointer instanceof SKU) {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('acm_sku');
$view = $view_builder->view($tree_pointer);
// Block add to cart render because Form API won't allow AJAX Formception.
$view['#no_add_to_cart'] = TRUE;
$dynamic_parts['add_to_cart'] = [
'entity_render' => ['#markup' => render($view)],
];
}
else {
$available_config = $tree_pointer['#available_config'];
foreach ($available_config as $key => $config) {
$options = [
'' => $dynamic_parts['configurables']['color']['#options'][''],
];
foreach ($config['values'] as $value) {
$options[$value['value_id']] = $value['label'];
}
// Sort config options before pushing them to the select list based on
// the config.
if ($helper->isAttributeSortable($key)) {
// Make sure the first element in the list is the empty option.
$sorted_options = [
'' => $dynamic_parts['configurables'][$key]['#options'][''],
];
$sorted_options += self::sortConfigOptions($options, $key);
}
else {
// Use this in case the attribute is not sortable as per the config.
$sorted_options = $options;
}
$dynamic_parts['configurables'][$key]['#options'] = $sorted_options;
}
}
return $dynamic_parts;
} | [
"public",
"static",
"function",
"configurableAjaxCallback",
"(",
"array",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
")",
"{",
"$",
"dynamic_parts",
"=",
"&",
"$",
"form",
"[",
"'ajax'",
"]",
";",
"$",
"configurables",
"=",
"$",
"form_state",
"->",
"getValue",
"(",
"'configurables'",
")",
";",
"/** @var \\Drupal\\acm_sku\\CartFormHelper $helper */",
"$",
"helper",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm_sku.cart_form_helper'",
")",
";",
"$",
"tree",
"=",
"$",
"form_state",
"->",
"get",
"(",
"'tree'",
")",
";",
"$",
"tree_pointer",
"=",
"&",
"$",
"tree",
"[",
"'options'",
"]",
";",
"foreach",
"(",
"$",
"configurables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"// Move the tree pointer if the selection is valid.",
"if",
"(",
"isset",
"(",
"$",
"tree_pointer",
"[",
"\"$key:$value\"",
"]",
")",
")",
"{",
"$",
"tree_pointer",
"=",
"&",
"$",
"tree_pointer",
"[",
"\"$key:$value\"",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"tree_pointer",
"instanceof",
"SKU",
")",
"{",
"$",
"view_builder",
"=",
"\\",
"Drupal",
"::",
"entityTypeManager",
"(",
")",
"->",
"getViewBuilder",
"(",
"'acm_sku'",
")",
";",
"$",
"view",
"=",
"$",
"view_builder",
"->",
"view",
"(",
"$",
"tree_pointer",
")",
";",
"// Block add to cart render because Form API won't allow AJAX Formception.",
"$",
"view",
"[",
"'#no_add_to_cart'",
"]",
"=",
"TRUE",
";",
"$",
"dynamic_parts",
"[",
"'add_to_cart'",
"]",
"=",
"[",
"'entity_render'",
"=>",
"[",
"'#markup'",
"=>",
"render",
"(",
"$",
"view",
")",
"]",
",",
"]",
";",
"}",
"else",
"{",
"$",
"available_config",
"=",
"$",
"tree_pointer",
"[",
"'#available_config'",
"]",
";",
"foreach",
"(",
"$",
"available_config",
"as",
"$",
"key",
"=>",
"$",
"config",
")",
"{",
"$",
"options",
"=",
"[",
"''",
"=>",
"$",
"dynamic_parts",
"[",
"'configurables'",
"]",
"[",
"'color'",
"]",
"[",
"'#options'",
"]",
"[",
"''",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"config",
"[",
"'values'",
"]",
"as",
"$",
"value",
")",
"{",
"$",
"options",
"[",
"$",
"value",
"[",
"'value_id'",
"]",
"]",
"=",
"$",
"value",
"[",
"'label'",
"]",
";",
"}",
"// Sort config options before pushing them to the select list based on",
"// the config.",
"if",
"(",
"$",
"helper",
"->",
"isAttributeSortable",
"(",
"$",
"key",
")",
")",
"{",
"// Make sure the first element in the list is the empty option.",
"$",
"sorted_options",
"=",
"[",
"''",
"=>",
"$",
"dynamic_parts",
"[",
"'configurables'",
"]",
"[",
"$",
"key",
"]",
"[",
"'#options'",
"]",
"[",
"''",
"]",
",",
"]",
";",
"$",
"sorted_options",
"+=",
"self",
"::",
"sortConfigOptions",
"(",
"$",
"options",
",",
"$",
"key",
")",
";",
"}",
"else",
"{",
"// Use this in case the attribute is not sortable as per the config.",
"$",
"sorted_options",
"=",
"$",
"options",
";",
"}",
"$",
"dynamic_parts",
"[",
"'configurables'",
"]",
"[",
"$",
"key",
"]",
"[",
"'#options'",
"]",
"=",
"$",
"sorted_options",
";",
"}",
"}",
"return",
"$",
"dynamic_parts",
";",
"}"
]
| Updates the form based on selections.
@param array $form
Array of form.
@param \Drupal\Core\Form\FormStateInterface $form_state
Values of form.
@return array
Array with dynamic parts of the form. | [
"Updates",
"the",
"form",
"based",
"on",
"selections",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L202-L267 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.deriveProductTree | public function deriveProductTree(SKU $sku) {
static $cache = [];
if (isset($cache[$sku->language()->getId()], $cache[$sku->language()->getId()][$sku->id()])) {
return $cache[$sku->language()->getId()][$sku->id()];
}
$tree = [
'parent' => $sku,
'products' => self::getChildren($sku),
'combinations' => [],
];
$configurables = unserialize(
$sku->get('field_configurable_attributes')->getString()
);
$tree['configurables'] = [];
foreach ($configurables as $configurable) {
$tree['configurables'][$configurable['code']] = $configurable;
}
$configurable_codes = array_keys($tree['configurables']);
foreach ($tree['products'] ?? [] as $sku_code => $sku_entity) {
$attributes = $sku_entity->get('attributes')->getValue();
$attributes = array_column($attributes, 'value', 'key');
foreach ($configurable_codes as $code) {
$value = $attributes[$code] ?? '';
if (empty($value)) {
continue;
}
$tree['combinations']['by_sku'][$sku_code][$code] = $value;
}
}
/** @var \Drupal\acm_sku\CartFormHelper $helper */
$helper = \Drupal::service('acm_sku.cart_form_helper');
$configurable_weights = $helper->getConfigurableAttributeWeights(
$sku->get('attribute_set')->getString()
);
// Sort configurables based on the config.
uasort($tree['configurables'], function ($a, $b) use ($configurable_weights) {
return $configurable_weights[$a['code']] - $configurable_weights[$b['code']];
});
$tree['options'] = Configurable::recursiveConfigurableTree(
$tree,
$tree['configurables']
);
$cache[$sku->language()->getId()][$sku->id()] = $tree;
return $tree;
} | php | public function deriveProductTree(SKU $sku) {
static $cache = [];
if (isset($cache[$sku->language()->getId()], $cache[$sku->language()->getId()][$sku->id()])) {
return $cache[$sku->language()->getId()][$sku->id()];
}
$tree = [
'parent' => $sku,
'products' => self::getChildren($sku),
'combinations' => [],
];
$configurables = unserialize(
$sku->get('field_configurable_attributes')->getString()
);
$tree['configurables'] = [];
foreach ($configurables as $configurable) {
$tree['configurables'][$configurable['code']] = $configurable;
}
$configurable_codes = array_keys($tree['configurables']);
foreach ($tree['products'] ?? [] as $sku_code => $sku_entity) {
$attributes = $sku_entity->get('attributes')->getValue();
$attributes = array_column($attributes, 'value', 'key');
foreach ($configurable_codes as $code) {
$value = $attributes[$code] ?? '';
if (empty($value)) {
continue;
}
$tree['combinations']['by_sku'][$sku_code][$code] = $value;
}
}
/** @var \Drupal\acm_sku\CartFormHelper $helper */
$helper = \Drupal::service('acm_sku.cart_form_helper');
$configurable_weights = $helper->getConfigurableAttributeWeights(
$sku->get('attribute_set')->getString()
);
// Sort configurables based on the config.
uasort($tree['configurables'], function ($a, $b) use ($configurable_weights) {
return $configurable_weights[$a['code']] - $configurable_weights[$b['code']];
});
$tree['options'] = Configurable::recursiveConfigurableTree(
$tree,
$tree['configurables']
);
$cache[$sku->language()->getId()][$sku->id()] = $tree;
return $tree;
} | [
"public",
"function",
"deriveProductTree",
"(",
"SKU",
"$",
"sku",
")",
"{",
"static",
"$",
"cache",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"cache",
"[",
"$",
"sku",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
"]",
",",
"$",
"cache",
"[",
"$",
"sku",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
"]",
"[",
"$",
"sku",
"->",
"id",
"(",
")",
"]",
")",
")",
"{",
"return",
"$",
"cache",
"[",
"$",
"sku",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
"]",
"[",
"$",
"sku",
"->",
"id",
"(",
")",
"]",
";",
"}",
"$",
"tree",
"=",
"[",
"'parent'",
"=>",
"$",
"sku",
",",
"'products'",
"=>",
"self",
"::",
"getChildren",
"(",
"$",
"sku",
")",
",",
"'combinations'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"configurables",
"=",
"unserialize",
"(",
"$",
"sku",
"->",
"get",
"(",
"'field_configurable_attributes'",
")",
"->",
"getString",
"(",
")",
")",
";",
"$",
"tree",
"[",
"'configurables'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"configurables",
"as",
"$",
"configurable",
")",
"{",
"$",
"tree",
"[",
"'configurables'",
"]",
"[",
"$",
"configurable",
"[",
"'code'",
"]",
"]",
"=",
"$",
"configurable",
";",
"}",
"$",
"configurable_codes",
"=",
"array_keys",
"(",
"$",
"tree",
"[",
"'configurables'",
"]",
")",
";",
"foreach",
"(",
"$",
"tree",
"[",
"'products'",
"]",
"??",
"[",
"]",
"as",
"$",
"sku_code",
"=>",
"$",
"sku_entity",
")",
"{",
"$",
"attributes",
"=",
"$",
"sku_entity",
"->",
"get",
"(",
"'attributes'",
")",
"->",
"getValue",
"(",
")",
";",
"$",
"attributes",
"=",
"array_column",
"(",
"$",
"attributes",
",",
"'value'",
",",
"'key'",
")",
";",
"foreach",
"(",
"$",
"configurable_codes",
"as",
"$",
"code",
")",
"{",
"$",
"value",
"=",
"$",
"attributes",
"[",
"$",
"code",
"]",
"??",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"$",
"tree",
"[",
"'combinations'",
"]",
"[",
"'by_sku'",
"]",
"[",
"$",
"sku_code",
"]",
"[",
"$",
"code",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"/** @var \\Drupal\\acm_sku\\CartFormHelper $helper */",
"$",
"helper",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm_sku.cart_form_helper'",
")",
";",
"$",
"configurable_weights",
"=",
"$",
"helper",
"->",
"getConfigurableAttributeWeights",
"(",
"$",
"sku",
"->",
"get",
"(",
"'attribute_set'",
")",
"->",
"getString",
"(",
")",
")",
";",
"// Sort configurables based on the config.",
"uasort",
"(",
"$",
"tree",
"[",
"'configurables'",
"]",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"configurable_weights",
")",
"{",
"return",
"$",
"configurable_weights",
"[",
"$",
"a",
"[",
"'code'",
"]",
"]",
"-",
"$",
"configurable_weights",
"[",
"$",
"b",
"[",
"'code'",
"]",
"]",
";",
"}",
")",
";",
"$",
"tree",
"[",
"'options'",
"]",
"=",
"Configurable",
"::",
"recursiveConfigurableTree",
"(",
"$",
"tree",
",",
"$",
"tree",
"[",
"'configurables'",
"]",
")",
";",
"$",
"cache",
"[",
"$",
"sku",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
"]",
"[",
"$",
"sku",
"->",
"id",
"(",
")",
"]",
"=",
"$",
"tree",
";",
"return",
"$",
"tree",
";",
"}"
]
| Builds a display tree.
Helps to determine which products belong to which combination of
configurables.
@param \Drupal\acm_sku\Entity\SKU $sku
Object of SKU.
@return array
Configurables tree. | [
"Builds",
"a",
"display",
"tree",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L474-L532 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.recursiveConfigurableTree | public static function recursiveConfigurableTree(array &$tree, array $available_config, array $current_config = []) {
$subtree = ['#available_config' => $available_config];
foreach ($available_config as $id => $config) {
$subtree_available_config = $available_config;
unset($subtree_available_config[$id]);
foreach ($config['values'] as $option) {
$value = $option['value_id'];
$subtree_current_config = array_merge($current_config, [$id => $value]);
if (count($subtree_available_config) > 0) {
$subtree["$id:$value"] = Configurable::recursiveConfigurableTree(
$tree,
$subtree_available_config,
$subtree_current_config
);
}
else {
$subtree["$id:$value"] = Configurable::findProductInTreeWithConfig(
$tree,
$subtree_current_config
);
}
}
}
return $subtree;
} | php | public static function recursiveConfigurableTree(array &$tree, array $available_config, array $current_config = []) {
$subtree = ['#available_config' => $available_config];
foreach ($available_config as $id => $config) {
$subtree_available_config = $available_config;
unset($subtree_available_config[$id]);
foreach ($config['values'] as $option) {
$value = $option['value_id'];
$subtree_current_config = array_merge($current_config, [$id => $value]);
if (count($subtree_available_config) > 0) {
$subtree["$id:$value"] = Configurable::recursiveConfigurableTree(
$tree,
$subtree_available_config,
$subtree_current_config
);
}
else {
$subtree["$id:$value"] = Configurable::findProductInTreeWithConfig(
$tree,
$subtree_current_config
);
}
}
}
return $subtree;
} | [
"public",
"static",
"function",
"recursiveConfigurableTree",
"(",
"array",
"&",
"$",
"tree",
",",
"array",
"$",
"available_config",
",",
"array",
"$",
"current_config",
"=",
"[",
"]",
")",
"{",
"$",
"subtree",
"=",
"[",
"'#available_config'",
"=>",
"$",
"available_config",
"]",
";",
"foreach",
"(",
"$",
"available_config",
"as",
"$",
"id",
"=>",
"$",
"config",
")",
"{",
"$",
"subtree_available_config",
"=",
"$",
"available_config",
";",
"unset",
"(",
"$",
"subtree_available_config",
"[",
"$",
"id",
"]",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'values'",
"]",
"as",
"$",
"option",
")",
"{",
"$",
"value",
"=",
"$",
"option",
"[",
"'value_id'",
"]",
";",
"$",
"subtree_current_config",
"=",
"array_merge",
"(",
"$",
"current_config",
",",
"[",
"$",
"id",
"=>",
"$",
"value",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"subtree_available_config",
")",
">",
"0",
")",
"{",
"$",
"subtree",
"[",
"\"$id:$value\"",
"]",
"=",
"Configurable",
"::",
"recursiveConfigurableTree",
"(",
"$",
"tree",
",",
"$",
"subtree_available_config",
",",
"$",
"subtree_current_config",
")",
";",
"}",
"else",
"{",
"$",
"subtree",
"[",
"\"$id:$value\"",
"]",
"=",
"Configurable",
"::",
"findProductInTreeWithConfig",
"(",
"$",
"tree",
",",
"$",
"subtree_current_config",
")",
";",
"}",
"}",
"}",
"return",
"$",
"subtree",
";",
"}"
]
| Creates subtrees based on available config.
@param array $tree
Tree of products.
@param array $available_config
Available configs.
@param array $current_config
Config of current product.
@return array
Subtree. | [
"Creates",
"subtrees",
"based",
"on",
"available",
"config",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L547-L575 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.findProductInTreeWithConfig | public static function findProductInTreeWithConfig(array $tree, array $config) {
if (isset($tree['products'])) {
$attributes = [];
foreach ($config as $key => $value) {
$attributes[$key] = $value;
}
foreach ($tree['combinations']['by_sku'] ?? [] as $sku => $sku_attributes) {
if (count(array_intersect_assoc($sku_attributes, $attributes)) === count($sku_attributes)) {
return $tree['products'][$sku];
}
}
}
return NULL;
} | php | public static function findProductInTreeWithConfig(array $tree, array $config) {
if (isset($tree['products'])) {
$attributes = [];
foreach ($config as $key => $value) {
$attributes[$key] = $value;
}
foreach ($tree['combinations']['by_sku'] ?? [] as $sku => $sku_attributes) {
if (count(array_intersect_assoc($sku_attributes, $attributes)) === count($sku_attributes)) {
return $tree['products'][$sku];
}
}
}
return NULL;
} | [
"public",
"static",
"function",
"findProductInTreeWithConfig",
"(",
"array",
"$",
"tree",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"tree",
"[",
"'products'",
"]",
")",
")",
"{",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"foreach",
"(",
"$",
"tree",
"[",
"'combinations'",
"]",
"[",
"'by_sku'",
"]",
"??",
"[",
"]",
"as",
"$",
"sku",
"=>",
"$",
"sku_attributes",
")",
"{",
"if",
"(",
"count",
"(",
"array_intersect_assoc",
"(",
"$",
"sku_attributes",
",",
"$",
"attributes",
")",
")",
"===",
"count",
"(",
"$",
"sku_attributes",
")",
")",
"{",
"return",
"$",
"tree",
"[",
"'products'",
"]",
"[",
"$",
"sku",
"]",
";",
"}",
"}",
"}",
"return",
"NULL",
";",
"}"
]
| Finds product in tree base on config.
@param array $tree
The whole configurable tree.
@param array $config
Config for the product.
@return \Drupal\acm_sku\Entity\SKU
Reference to SKU in existing tree. | [
"Finds",
"product",
"in",
"tree",
"base",
"on",
"config",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L588-L603 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.getAttributeValue | public function getAttributeValue($sku, $key) {
$id = $sku instanceof SKUInterface ? $sku->id() : $sku;
$query = \Drupal::database()->select('acm_sku__attributes', 'acm_sku__attributes');
$query->addField('acm_sku__attributes', 'attributes_value');
$query->condition("acm_sku__attributes.entity_id", $id);
$query->condition("acm_sku__attributes.attributes_key", $key);
return $query->execute()->fetchField();
} | php | public function getAttributeValue($sku, $key) {
$id = $sku instanceof SKUInterface ? $sku->id() : $sku;
$query = \Drupal::database()->select('acm_sku__attributes', 'acm_sku__attributes');
$query->addField('acm_sku__attributes', 'attributes_value');
$query->condition("acm_sku__attributes.entity_id", $id);
$query->condition("acm_sku__attributes.attributes_key", $key);
return $query->execute()->fetchField();
} | [
"public",
"function",
"getAttributeValue",
"(",
"$",
"sku",
",",
"$",
"key",
")",
"{",
"$",
"id",
"=",
"$",
"sku",
"instanceof",
"SKUInterface",
"?",
"$",
"sku",
"->",
"id",
"(",
")",
":",
"$",
"sku",
";",
"$",
"query",
"=",
"\\",
"Drupal",
"::",
"database",
"(",
")",
"->",
"select",
"(",
"'acm_sku__attributes'",
",",
"'acm_sku__attributes'",
")",
";",
"$",
"query",
"->",
"addField",
"(",
"'acm_sku__attributes'",
",",
"'attributes_value'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"\"acm_sku__attributes.entity_id\"",
",",
"$",
"id",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"\"acm_sku__attributes.attributes_key\"",
",",
"$",
"key",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchField",
"(",
")",
";",
"}"
]
| Get attribute value from key-value field.
@param int|\Drupal\acm_sku\Entity\SKUInterface $sku
Entity id of the SKU.
@param string $key
Name of attribute.
@return string|null
Value of field or null if empty. | [
"Get",
"attribute",
"value",
"from",
"key",
"-",
"value",
"field",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L616-L624 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.extractConfigurableOptions | protected function extractConfigurableOptions($attribute_set, array $configurable_options) {
/** @var \Drupal\acm_sku\CartFormHelper $helper */
$helper = \Drupal::service('acm_sku.cart_form_helper');
// Load existing options.
$existing_options = $helper->getConfigurableAttributeWeights($attribute_set);
// Transform incoming options.
foreach ($configurable_options as $configurable) {
$existing_options[$configurable['code']] = $configurable['position'];
}
// Save options.
$helper->setConfigurableAttributeWeights($attribute_set, $existing_options);
} | php | protected function extractConfigurableOptions($attribute_set, array $configurable_options) {
/** @var \Drupal\acm_sku\CartFormHelper $helper */
$helper = \Drupal::service('acm_sku.cart_form_helper');
// Load existing options.
$existing_options = $helper->getConfigurableAttributeWeights($attribute_set);
// Transform incoming options.
foreach ($configurable_options as $configurable) {
$existing_options[$configurable['code']] = $configurable['position'];
}
// Save options.
$helper->setConfigurableAttributeWeights($attribute_set, $existing_options);
} | [
"protected",
"function",
"extractConfigurableOptions",
"(",
"$",
"attribute_set",
",",
"array",
"$",
"configurable_options",
")",
"{",
"/** @var \\Drupal\\acm_sku\\CartFormHelper $helper */",
"$",
"helper",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm_sku.cart_form_helper'",
")",
";",
"// Load existing options.",
"$",
"existing_options",
"=",
"$",
"helper",
"->",
"getConfigurableAttributeWeights",
"(",
"$",
"attribute_set",
")",
";",
"// Transform incoming options.",
"foreach",
"(",
"$",
"configurable_options",
"as",
"$",
"configurable",
")",
"{",
"$",
"existing_options",
"[",
"$",
"configurable",
"[",
"'code'",
"]",
"]",
"=",
"$",
"configurable",
"[",
"'position'",
"]",
";",
"}",
"// Save options.",
"$",
"helper",
"->",
"setConfigurableAttributeWeights",
"(",
"$",
"attribute_set",
",",
"$",
"existing_options",
")",
";",
"}"
]
| Extract configurable options.
Extract new configurable options during import and store them.
@param string $attribute_set
Attribute set.
@param array $configurable_options
Array with configurable options. | [
"Extract",
"configurable",
"options",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L695-L709 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.sortConfigOptions | public static function sortConfigOptions(array &$options, $attribute_code) {
$sorted_options = [];
$query = \Drupal::database()->select('taxonomy_term_field_data', 'ttfd');
$query->fields('ttfd', ['tid', 'weight']);
$query->join('taxonomy_term__field_sku_attribute_code', 'ttfsac', 'ttfsac.entity_id = ttfd.tid');
$query->join('taxonomy_term__field_sku_option_id', 'ttfsoi', 'ttfsoi.entity_id = ttfd.tid');
$query->fields('ttfsoi', ['field_sku_option_id_value']);
$query->condition('ttfd.vid', ProductOptionsManager::PRODUCT_OPTIONS_VOCABULARY);
$query->condition('ttfsac.field_sku_attribute_code_value', $attribute_code);
$query->condition('ttfsoi.field_sku_option_id_value', array_keys($options), 'IN');
$query->distinct();
$query->orderBy('weight', 'ASC');
$tids = $query->execute()->fetchAllAssoc('tid');
foreach ($tids as $tid => $values) {
$sorted_options[$values->field_sku_option_id_value] = $options[$values->field_sku_option_id_value];
}
return $sorted_options;
} | php | public static function sortConfigOptions(array &$options, $attribute_code) {
$sorted_options = [];
$query = \Drupal::database()->select('taxonomy_term_field_data', 'ttfd');
$query->fields('ttfd', ['tid', 'weight']);
$query->join('taxonomy_term__field_sku_attribute_code', 'ttfsac', 'ttfsac.entity_id = ttfd.tid');
$query->join('taxonomy_term__field_sku_option_id', 'ttfsoi', 'ttfsoi.entity_id = ttfd.tid');
$query->fields('ttfsoi', ['field_sku_option_id_value']);
$query->condition('ttfd.vid', ProductOptionsManager::PRODUCT_OPTIONS_VOCABULARY);
$query->condition('ttfsac.field_sku_attribute_code_value', $attribute_code);
$query->condition('ttfsoi.field_sku_option_id_value', array_keys($options), 'IN');
$query->distinct();
$query->orderBy('weight', 'ASC');
$tids = $query->execute()->fetchAllAssoc('tid');
foreach ($tids as $tid => $values) {
$sorted_options[$values->field_sku_option_id_value] = $options[$values->field_sku_option_id_value];
}
return $sorted_options;
} | [
"public",
"static",
"function",
"sortConfigOptions",
"(",
"array",
"&",
"$",
"options",
",",
"$",
"attribute_code",
")",
"{",
"$",
"sorted_options",
"=",
"[",
"]",
";",
"$",
"query",
"=",
"\\",
"Drupal",
"::",
"database",
"(",
")",
"->",
"select",
"(",
"'taxonomy_term_field_data'",
",",
"'ttfd'",
")",
";",
"$",
"query",
"->",
"fields",
"(",
"'ttfd'",
",",
"[",
"'tid'",
",",
"'weight'",
"]",
")",
";",
"$",
"query",
"->",
"join",
"(",
"'taxonomy_term__field_sku_attribute_code'",
",",
"'ttfsac'",
",",
"'ttfsac.entity_id = ttfd.tid'",
")",
";",
"$",
"query",
"->",
"join",
"(",
"'taxonomy_term__field_sku_option_id'",
",",
"'ttfsoi'",
",",
"'ttfsoi.entity_id = ttfd.tid'",
")",
";",
"$",
"query",
"->",
"fields",
"(",
"'ttfsoi'",
",",
"[",
"'field_sku_option_id_value'",
"]",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'ttfd.vid'",
",",
"ProductOptionsManager",
"::",
"PRODUCT_OPTIONS_VOCABULARY",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'ttfsac.field_sku_attribute_code_value'",
",",
"$",
"attribute_code",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'ttfsoi.field_sku_option_id_value'",
",",
"array_keys",
"(",
"$",
"options",
")",
",",
"'IN'",
")",
";",
"$",
"query",
"->",
"distinct",
"(",
")",
";",
"$",
"query",
"->",
"orderBy",
"(",
"'weight'",
",",
"'ASC'",
")",
";",
"$",
"tids",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAllAssoc",
"(",
"'tid'",
")",
";",
"foreach",
"(",
"$",
"tids",
"as",
"$",
"tid",
"=>",
"$",
"values",
")",
"{",
"$",
"sorted_options",
"[",
"$",
"values",
"->",
"field_sku_option_id_value",
"]",
"=",
"$",
"options",
"[",
"$",
"values",
"->",
"field_sku_option_id_value",
"]",
";",
"}",
"return",
"$",
"sorted_options",
";",
"}"
]
| Helper function to sort config options based on taxonomy term weight.
@param array $options
Option values keyed by option id.
@param string $attribute_code
Attribute name.
@return array
Array of options sorted based on term weight. | [
"Helper",
"function",
"to",
"sort",
"config",
"options",
"based",
"on",
"taxonomy",
"term",
"weight",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L751-L771 | train |
acquia/commerce-manager | modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php | Configurable.getChildren | public static function getChildren(SKU $sku) {
$children = [];
foreach ($sku->get('field_configured_skus')->getValue() as $child) {
if (empty($child['value'])) {
continue;
}
$child_sku = SKU::loadFromSku($child['value']);
if ($child_sku instanceof SKU) {
$children[$child_sku->getSKU()] = $child_sku;
}
}
return $children;
} | php | public static function getChildren(SKU $sku) {
$children = [];
foreach ($sku->get('field_configured_skus')->getValue() as $child) {
if (empty($child['value'])) {
continue;
}
$child_sku = SKU::loadFromSku($child['value']);
if ($child_sku instanceof SKU) {
$children[$child_sku->getSKU()] = $child_sku;
}
}
return $children;
} | [
"public",
"static",
"function",
"getChildren",
"(",
"SKU",
"$",
"sku",
")",
"{",
"$",
"children",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sku",
"->",
"get",
"(",
"'field_configured_skus'",
")",
"->",
"getValue",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"child",
"[",
"'value'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"child_sku",
"=",
"SKU",
"::",
"loadFromSku",
"(",
"$",
"child",
"[",
"'value'",
"]",
")",
";",
"if",
"(",
"$",
"child_sku",
"instanceof",
"SKU",
")",
"{",
"$",
"children",
"[",
"$",
"child_sku",
"->",
"getSKU",
"(",
")",
"]",
"=",
"$",
"child_sku",
";",
"}",
"}",
"return",
"$",
"children",
";",
"}"
]
| Wrapper function to get available children for a configurable SKU.
@param \Drupal\acm_sku\Entity\SKU $sku
Configurable SKU.
@return array
Full loaded child SKUs. | [
"Wrapper",
"function",
"to",
"get",
"available",
"children",
"for",
"a",
"configurable",
"SKU",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php#L782-L797 | train |
acquia/commerce-manager | modules/acm/src/Form/ConnectorSettingsForm.php | ConnectorSettingsForm.getSkuFieldName | protected function getSkuFieldName($node_type) {
$fields = $this->entityFieldManager
->getFieldDefinitions('node', $node_type);
// Determine which field is used for sku references based on the configured
// product node type.
$sku_field_name = FALSE;
foreach ($fields as $field_name => $field_instance) {
$field_type = $field_instance->getType();
if ($field_type == 'sku') {
$sku_field_name = $field_name;
break;
}
}
return $sku_field_name;
} | php | protected function getSkuFieldName($node_type) {
$fields = $this->entityFieldManager
->getFieldDefinitions('node', $node_type);
// Determine which field is used for sku references based on the configured
// product node type.
$sku_field_name = FALSE;
foreach ($fields as $field_name => $field_instance) {
$field_type = $field_instance->getType();
if ($field_type == 'sku') {
$sku_field_name = $field_name;
break;
}
}
return $sku_field_name;
} | [
"protected",
"function",
"getSkuFieldName",
"(",
"$",
"node_type",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"entityFieldManager",
"->",
"getFieldDefinitions",
"(",
"'node'",
",",
"$",
"node_type",
")",
";",
"// Determine which field is used for sku references based on the configured",
"// product node type.",
"$",
"sku_field_name",
"=",
"FALSE",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field_name",
"=>",
"$",
"field_instance",
")",
"{",
"$",
"field_type",
"=",
"$",
"field_instance",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"$",
"field_type",
"==",
"'sku'",
")",
"{",
"$",
"sku_field_name",
"=",
"$",
"field_name",
";",
"break",
";",
"}",
"}",
"return",
"$",
"sku_field_name",
";",
"}"
]
| Gets the SKU field on a given node type.
@param string $node_type
The node type to scan.
@return string
The SKU field name. | [
"Gets",
"the",
"SKU",
"field",
"on",
"a",
"given",
"node",
"type",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Form/ConnectorSettingsForm.php#L307-L323 | train |
acquia/commerce-manager | modules/acm/src/Form/ConnectorSettingsForm.php | ConnectorSettingsForm.getCategoryFieldName | protected function getCategoryFieldName($node_type, $vid) {
$fields = $this->entityFieldManager
->getFieldDefinitions('node', $node_type);
// Determine which field is used for categories based on the configured
// product node type.
$category_field_name = FALSE;
foreach ($fields as $field_name => $field_instance) {
$field_type = $field_instance->getType();
if ($field_type != 'entity_reference') {
continue;
}
$settings = $field_instance->getSettings();
if ($settings['target_type'] != 'taxonomy_term') {
continue;
}
if (in_array($vid, $settings['handler_settings']['target_bundles'])) {
$category_field_name = $field_name;
break;
}
}
return $category_field_name;
} | php | protected function getCategoryFieldName($node_type, $vid) {
$fields = $this->entityFieldManager
->getFieldDefinitions('node', $node_type);
// Determine which field is used for categories based on the configured
// product node type.
$category_field_name = FALSE;
foreach ($fields as $field_name => $field_instance) {
$field_type = $field_instance->getType();
if ($field_type != 'entity_reference') {
continue;
}
$settings = $field_instance->getSettings();
if ($settings['target_type'] != 'taxonomy_term') {
continue;
}
if (in_array($vid, $settings['handler_settings']['target_bundles'])) {
$category_field_name = $field_name;
break;
}
}
return $category_field_name;
} | [
"protected",
"function",
"getCategoryFieldName",
"(",
"$",
"node_type",
",",
"$",
"vid",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"entityFieldManager",
"->",
"getFieldDefinitions",
"(",
"'node'",
",",
"$",
"node_type",
")",
";",
"// Determine which field is used for categories based on the configured",
"// product node type.",
"$",
"category_field_name",
"=",
"FALSE",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field_name",
"=>",
"$",
"field_instance",
")",
"{",
"$",
"field_type",
"=",
"$",
"field_instance",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"$",
"field_type",
"!=",
"'entity_reference'",
")",
"{",
"continue",
";",
"}",
"$",
"settings",
"=",
"$",
"field_instance",
"->",
"getSettings",
"(",
")",
";",
"if",
"(",
"$",
"settings",
"[",
"'target_type'",
"]",
"!=",
"'taxonomy_term'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"vid",
",",
"$",
"settings",
"[",
"'handler_settings'",
"]",
"[",
"'target_bundles'",
"]",
")",
")",
"{",
"$",
"category_field_name",
"=",
"$",
"field_name",
";",
"break",
";",
"}",
"}",
"return",
"$",
"category_field_name",
";",
"}"
]
| Gets the field used to store the category on a given node type.
@param string $node_type
The node type to scan.
@param string $vid
The vocabulary id to check for.
@return string
The Categories field name. | [
"Gets",
"the",
"field",
"used",
"to",
"store",
"the",
"category",
"on",
"a",
"given",
"node",
"type",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Form/ConnectorSettingsForm.php#L336-L361 | train |
acquia/commerce-manager | modules/acm/src/Form/ConnectorSettingsForm.php | ConnectorSettingsForm.getFilterFormats | public function getFilterFormats() {
$options = [];
$formats = filter_formats($this->currentUser);
foreach ($formats as $format) {
$options[$format->id()] = $format->label();
}
return $options;
} | php | public function getFilterFormats() {
$options = [];
$formats = filter_formats($this->currentUser);
foreach ($formats as $format) {
$options[$format->id()] = $format->label();
}
return $options;
} | [
"public",
"function",
"getFilterFormats",
"(",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"formats",
"=",
"filter_formats",
"(",
"$",
"this",
"->",
"currentUser",
")",
";",
"foreach",
"(",
"$",
"formats",
"as",
"$",
"format",
")",
"{",
"$",
"options",
"[",
"$",
"format",
"->",
"id",
"(",
")",
"]",
"=",
"$",
"format",
"->",
"label",
"(",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
]
| Get all filter formats available to the user.
@return array
An array of available html filters. | [
"Get",
"all",
"filter",
"formats",
"available",
"to",
"the",
"user",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Form/ConnectorSettingsForm.php#L369-L376 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/ReadonlyInput.php | ReadonlyInput.propertyDisplayFactory | public function propertyDisplayFactory()
{
if (!isset($this->propertyDisplayFactory)) {
throw new RuntimeException(
sprintf('Property Display Factory is not defined for "%s"', get_class($this))
);
}
return $this->propertyDisplayFactory;
} | php | public function propertyDisplayFactory()
{
if (!isset($this->propertyDisplayFactory)) {
throw new RuntimeException(
sprintf('Property Display Factory is not defined for "%s"', get_class($this))
);
}
return $this->propertyDisplayFactory;
} | [
"public",
"function",
"propertyDisplayFactory",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"propertyDisplayFactory",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Property Display Factory is not defined for \"%s\"'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"propertyDisplayFactory",
";",
"}"
]
| Retrieve the property display factory.
@throws RuntimeException If the property display factory was not previously set.
@return FactoryInterface | [
"Retrieve",
"the",
"property",
"display",
"factory",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/ReadonlyInput.php#L58-L67 | train |
acquia/commerce-manager | modules/acm_checkout/src/Plugin/CheckoutFlow/CheckoutFlowWithPanesBase.php | CheckoutFlowWithPanesBase.getPaneConfiguration | protected function getPaneConfiguration($pane_id) {
$pane_configuration = [];
if (isset($this->configuration['panes'][$pane_id])) {
$pane_configuration = $this->configuration['panes'][$pane_id];
}
return $pane_configuration;
} | php | protected function getPaneConfiguration($pane_id) {
$pane_configuration = [];
if (isset($this->configuration['panes'][$pane_id])) {
$pane_configuration = $this->configuration['panes'][$pane_id];
}
return $pane_configuration;
} | [
"protected",
"function",
"getPaneConfiguration",
"(",
"$",
"pane_id",
")",
"{",
"$",
"pane_configuration",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'panes'",
"]",
"[",
"$",
"pane_id",
"]",
")",
")",
"{",
"$",
"pane_configuration",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'panes'",
"]",
"[",
"$",
"pane_id",
"]",
";",
"}",
"return",
"$",
"pane_configuration",
";",
"}"
]
| Gets the configuration for the given pane.
@param string $pane_id
The pane ID.
@return array
The pane configuration. | [
"Gets",
"the",
"configuration",
"for",
"the",
"given",
"pane",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutFlow/CheckoutFlowWithPanesBase.php#L177-L184 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/StructureContainerTrait.php | StructureContainerTrait.setDisplay | public function setDisplay($display)
{
if ($display === null) {
$this->display = null;
return $this;
}
if (!is_string($display)) {
throw new InvalidArgumentException(sprintf(
'Layout must be a string, received %s',
(is_object($display) ? get_class($display) : gettype($display))
));
}
$supportedLayouts = $this->supportedDisplayLayouts();
if (!in_array($display, $supportedLayouts)) {
throw new OutOfBoundsException(sprintf(
'Unsupported layout [%s]; must be one of %s',
$display,
implode(', ', $supportedLayouts)
));
}
$this->display = $display;
return $this;
} | php | public function setDisplay($display)
{
if ($display === null) {
$this->display = null;
return $this;
}
if (!is_string($display)) {
throw new InvalidArgumentException(sprintf(
'Layout must be a string, received %s',
(is_object($display) ? get_class($display) : gettype($display))
));
}
$supportedLayouts = $this->supportedDisplayLayouts();
if (!in_array($display, $supportedLayouts)) {
throw new OutOfBoundsException(sprintf(
'Unsupported layout [%s]; must be one of %s',
$display,
implode(', ', $supportedLayouts)
));
}
$this->display = $display;
return $this;
} | [
"public",
"function",
"setDisplay",
"(",
"$",
"display",
")",
"{",
"if",
"(",
"$",
"display",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"display",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"display",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Layout must be a string, received %s'",
",",
"(",
"is_object",
"(",
"$",
"display",
")",
"?",
"get_class",
"(",
"$",
"display",
")",
":",
"gettype",
"(",
"$",
"display",
")",
")",
")",
")",
";",
"}",
"$",
"supportedLayouts",
"=",
"$",
"this",
"->",
"supportedDisplayLayouts",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"display",
",",
"$",
"supportedLayouts",
")",
")",
"{",
"throw",
"new",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Unsupported layout [%s]; must be one of %s'",
",",
"$",
"display",
",",
"implode",
"(",
"', '",
",",
"$",
"supportedLayouts",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"display",
"=",
"$",
"display",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the property's display layout.
@param string $display The layout for the tickable elements.
@throws InvalidArgumentException If the given layout is invalid.
@throws OutOfBoundsException If the given layout is unsupported.
@return self | [
"Set",
"the",
"property",
"s",
"display",
"layout",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/StructureContainerTrait.php#L35-L62 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/StructureContainerTrait.php | StructureContainerTrait.displays | public function displays()
{
$supported = $this->supportedDisplayLayouts();
$displays = [];
foreach ($supported as $display) {
$displays[$display] = ($display === $this->display());
}
return $displays;
} | php | public function displays()
{
$supported = $this->supportedDisplayLayouts();
$displays = [];
foreach ($supported as $display) {
$displays[$display] = ($display === $this->display());
}
return $displays;
} | [
"public",
"function",
"displays",
"(",
")",
"{",
"$",
"supported",
"=",
"$",
"this",
"->",
"supportedDisplayLayouts",
"(",
")",
";",
"$",
"displays",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"supported",
"as",
"$",
"display",
")",
"{",
"$",
"displays",
"[",
"$",
"display",
"]",
"=",
"(",
"$",
"display",
"===",
"$",
"this",
"->",
"display",
"(",
")",
")",
";",
"}",
"return",
"$",
"displays",
";",
"}"
]
| Retrieve the display layouts; for templating.
@return array | [
"Retrieve",
"the",
"display",
"layouts",
";",
"for",
"templating",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/StructureContainerTrait.php#L83-L92 | train |
acquia/commerce-manager | modules/acm_promotion/src/Commands/AcmPromotionCommands.php | AcmPromotionCommands.synPromotions | public function synPromotions(array $options = ['types' => NULL]) {
if ($types = $options['types']) {
$this->logger->notice(dt('Synchronizing all @types commerce promotions, this usually takes some time...', ['@types' => $types]));
$types = explode(',', $types);
$types = array_map('trim', $types);
$this->acmPromotionsManager->syncPromotions($types);
}
else {
$this->logger->notice(dt('Synchronizing all commerce promotions, this usually takes some time...'));
$this->acmPromotionsManager->syncPromotions();
}
$this->logger->notice(dt('Promotion sync completed.'));
} | php | public function synPromotions(array $options = ['types' => NULL]) {
if ($types = $options['types']) {
$this->logger->notice(dt('Synchronizing all @types commerce promotions, this usually takes some time...', ['@types' => $types]));
$types = explode(',', $types);
$types = array_map('trim', $types);
$this->acmPromotionsManager->syncPromotions($types);
}
else {
$this->logger->notice(dt('Synchronizing all commerce promotions, this usually takes some time...'));
$this->acmPromotionsManager->syncPromotions();
}
$this->logger->notice(dt('Promotion sync completed.'));
} | [
"public",
"function",
"synPromotions",
"(",
"array",
"$",
"options",
"=",
"[",
"'types'",
"=>",
"NULL",
"]",
")",
"{",
"if",
"(",
"$",
"types",
"=",
"$",
"options",
"[",
"'types'",
"]",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"dt",
"(",
"'Synchronizing all @types commerce promotions, this usually takes some time...'",
",",
"[",
"'@types'",
"=>",
"$",
"types",
"]",
")",
")",
";",
"$",
"types",
"=",
"explode",
"(",
"','",
",",
"$",
"types",
")",
";",
"$",
"types",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"types",
")",
";",
"$",
"this",
"->",
"acmPromotionsManager",
"->",
"syncPromotions",
"(",
"$",
"types",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"dt",
"(",
"'Synchronizing all commerce promotions, this usually takes some time...'",
")",
")",
";",
"$",
"this",
"->",
"acmPromotionsManager",
"->",
"syncPromotions",
"(",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"dt",
"(",
"'Promotion sync completed.'",
")",
")",
";",
"}"
]
| Run a full synchronization of all commerce promotion records.
@param array $options
Command Options.
@command acm_promotion:sync-promotions
@option types Type of promotions that need to be synced.
@validate-module-enabled acm_promotion
@aliases acspm,sync-commerce-promotions
@usage drush acspm
Run a full synchronization of all available promotions.
@usage drush acspm --types=cart
Run a full synchronization of all available cart promotions. | [
"Run",
"a",
"full",
"synchronization",
"of",
"all",
"commerce",
"promotion",
"records",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/Commands/AcmPromotionCommands.php#L56-L69 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Template/Object/CollectionTemplate.php | CollectionTemplate.searchWidget | public function searchWidget()
{
$widget = $this->widgetFactory()->create(SearchWidget::class);
$widget->setObjType($this->objType());
$listIdent = $this->metadataListIdent();
// Note that if the ident doesn't match a list,
// it will return basicly every properties of the object
$widget->setCollectionIdent($listIdent);
return $widget;
} | php | public function searchWidget()
{
$widget = $this->widgetFactory()->create(SearchWidget::class);
$widget->setObjType($this->objType());
$listIdent = $this->metadataListIdent();
// Note that if the ident doesn't match a list,
// it will return basicly every properties of the object
$widget->setCollectionIdent($listIdent);
return $widget;
} | [
"public",
"function",
"searchWidget",
"(",
")",
"{",
"$",
"widget",
"=",
"$",
"this",
"->",
"widgetFactory",
"(",
")",
"->",
"create",
"(",
"SearchWidget",
"::",
"class",
")",
";",
"$",
"widget",
"->",
"setObjType",
"(",
"$",
"this",
"->",
"objType",
"(",
")",
")",
";",
"$",
"listIdent",
"=",
"$",
"this",
"->",
"metadataListIdent",
"(",
")",
";",
"// Note that if the ident doesn't match a list,",
"// it will return basicly every properties of the object",
"$",
"widget",
"->",
"setCollectionIdent",
"(",
"$",
"listIdent",
")",
";",
"return",
"$",
"widget",
";",
"}"
]
| Sets the search widget accodingly
Uses the "default_search_list" ident that should point
on ident in the "lists"
@return \Charcoal\Admin\Widget\SearchWidget | [
"Sets",
"the",
"search",
"widget",
"accodingly",
"Uses",
"the",
"default_search_list",
"ident",
"that",
"should",
"point",
"on",
"ident",
"in",
"the",
"lists"
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/Object/CollectionTemplate.php#L64-L76 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/SearchWidget.php | SearchWidget.dataFromObject | public function dataFromObject()
{
$obj = $this->proto();
$metadata = $obj->metadata();
$adminMetadata = isset($metadata['admin']) ? $metadata['admin'] : null;
$collectionIdent = $this->collectionIdent();
if (!$collectionIdent) {
$collectionIdent = isset($adminMetadata['default_list']) ? $adminMetadata['default_list'] : '';
}
if (isset($adminMetadata['lists'][$collectionIdent])) {
return $adminMetadata['lists'][$collectionIdent];
} else {
return [];
}
} | php | public function dataFromObject()
{
$obj = $this->proto();
$metadata = $obj->metadata();
$adminMetadata = isset($metadata['admin']) ? $metadata['admin'] : null;
$collectionIdent = $this->collectionIdent();
if (!$collectionIdent) {
$collectionIdent = isset($adminMetadata['default_list']) ? $adminMetadata['default_list'] : '';
}
if (isset($adminMetadata['lists'][$collectionIdent])) {
return $adminMetadata['lists'][$collectionIdent];
} else {
return [];
}
} | [
"public",
"function",
"dataFromObject",
"(",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"proto",
"(",
")",
";",
"$",
"metadata",
"=",
"$",
"obj",
"->",
"metadata",
"(",
")",
";",
"$",
"adminMetadata",
"=",
"isset",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
")",
"?",
"$",
"metadata",
"[",
"'admin'",
"]",
":",
"null",
";",
"$",
"collectionIdent",
"=",
"$",
"this",
"->",
"collectionIdent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collectionIdent",
")",
"{",
"$",
"collectionIdent",
"=",
"isset",
"(",
"$",
"adminMetadata",
"[",
"'default_list'",
"]",
")",
"?",
"$",
"adminMetadata",
"[",
"'default_list'",
"]",
":",
"''",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"adminMetadata",
"[",
"'lists'",
"]",
"[",
"$",
"collectionIdent",
"]",
")",
")",
"{",
"return",
"$",
"adminMetadata",
"[",
"'lists'",
"]",
"[",
"$",
"collectionIdent",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}"
]
| Fetch metadata from current obj_type
@return array List of metadata. | [
"Fetch",
"metadata",
"from",
"current",
"obj_type"
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SearchWidget.php#L45-L60 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/SearchWidget.php | SearchWidget.propertiesIdents | public function propertiesIdents()
{
$metadata = $this->proto()->metadata();
if (isset($metadata['admin']['lists'])) {
$adminMetadata = $metadata['admin'];
$collectionIdent = $this->collectionIdent();
if (isset($adminMetadata['lists'][$collectionIdent]['properties'])) {
return $adminMetadata['lists'][$collectionIdent]['properties'];
}
}
return [];
} | php | public function propertiesIdents()
{
$metadata = $this->proto()->metadata();
if (isset($metadata['admin']['lists'])) {
$adminMetadata = $metadata['admin'];
$collectionIdent = $this->collectionIdent();
if (isset($adminMetadata['lists'][$collectionIdent]['properties'])) {
return $adminMetadata['lists'][$collectionIdent]['properties'];
}
}
return [];
} | [
"public",
"function",
"propertiesIdents",
"(",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"proto",
"(",
")",
"->",
"metadata",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
"[",
"'lists'",
"]",
")",
")",
"{",
"$",
"adminMetadata",
"=",
"$",
"metadata",
"[",
"'admin'",
"]",
";",
"$",
"collectionIdent",
"=",
"$",
"this",
"->",
"collectionIdent",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"adminMetadata",
"[",
"'lists'",
"]",
"[",
"$",
"collectionIdent",
"]",
"[",
"'properties'",
"]",
")",
")",
"{",
"return",
"$",
"adminMetadata",
"[",
"'lists'",
"]",
"[",
"$",
"collectionIdent",
"]",
"[",
"'properties'",
"]",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
]
| Retrieve the property keys to search in the collection.
@return array | [
"Retrieve",
"the",
"property",
"keys",
"to",
"search",
"in",
"the",
"collection",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SearchWidget.php#L101-L113 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.parseActions | protected function parseActions(array $actions, $renderer = false)
{
$this->actionsPriority = $this->defaultActionPriority();
$parsedActions = [];
foreach ($actions as $ident => $action) {
$ident = $this->parseActionIdent($ident, $action);
$action = $this->parseActionItem($action, $ident, $renderer);
if (!isset($action['priority'])) {
$action['priority'] = $this->actionsPriority++;
}
if (isset($parsedActions[$ident])) {
$hasPriority = ($action['priority'] > $parsedActions[$ident]['priority']);
if ($hasPriority || $action['isSubmittable']) {
$parsedActions[$ident] = array_replace($parsedActions[$ident], $action);
} else {
$parsedActions[$ident] = array_replace($action, $parsedActions[$ident]);
}
} else {
$parsedActions[$ident] = $action;
}
}
usort($parsedActions, [ $this, 'sortActionsByPriority' ]);
while (($first = reset($parsedActions)) && $first['isSeparator']) {
array_shift($parsedActions);
}
while (($last = end($parsedActions)) && $last['isSeparator']) {
array_pop($parsedActions);
}
return $parsedActions;
} | php | protected function parseActions(array $actions, $renderer = false)
{
$this->actionsPriority = $this->defaultActionPriority();
$parsedActions = [];
foreach ($actions as $ident => $action) {
$ident = $this->parseActionIdent($ident, $action);
$action = $this->parseActionItem($action, $ident, $renderer);
if (!isset($action['priority'])) {
$action['priority'] = $this->actionsPriority++;
}
if (isset($parsedActions[$ident])) {
$hasPriority = ($action['priority'] > $parsedActions[$ident]['priority']);
if ($hasPriority || $action['isSubmittable']) {
$parsedActions[$ident] = array_replace($parsedActions[$ident], $action);
} else {
$parsedActions[$ident] = array_replace($action, $parsedActions[$ident]);
}
} else {
$parsedActions[$ident] = $action;
}
}
usort($parsedActions, [ $this, 'sortActionsByPriority' ]);
while (($first = reset($parsedActions)) && $first['isSeparator']) {
array_shift($parsedActions);
}
while (($last = end($parsedActions)) && $last['isSeparator']) {
array_pop($parsedActions);
}
return $parsedActions;
} | [
"protected",
"function",
"parseActions",
"(",
"array",
"$",
"actions",
",",
"$",
"renderer",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"actionsPriority",
"=",
"$",
"this",
"->",
"defaultActionPriority",
"(",
")",
";",
"$",
"parsedActions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"ident",
"=>",
"$",
"action",
")",
"{",
"$",
"ident",
"=",
"$",
"this",
"->",
"parseActionIdent",
"(",
"$",
"ident",
",",
"$",
"action",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"parseActionItem",
"(",
"$",
"action",
",",
"$",
"ident",
",",
"$",
"renderer",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"action",
"[",
"'priority'",
"]",
")",
")",
"{",
"$",
"action",
"[",
"'priority'",
"]",
"=",
"$",
"this",
"->",
"actionsPriority",
"++",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
")",
")",
"{",
"$",
"hasPriority",
"=",
"(",
"$",
"action",
"[",
"'priority'",
"]",
">",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
"[",
"'priority'",
"]",
")",
";",
"if",
"(",
"$",
"hasPriority",
"||",
"$",
"action",
"[",
"'isSubmittable'",
"]",
")",
"{",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
"=",
"array_replace",
"(",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
",",
"$",
"action",
")",
";",
"}",
"else",
"{",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
"=",
"array_replace",
"(",
"$",
"action",
",",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"parsedActions",
"[",
"$",
"ident",
"]",
"=",
"$",
"action",
";",
"}",
"}",
"usort",
"(",
"$",
"parsedActions",
",",
"[",
"$",
"this",
",",
"'sortActionsByPriority'",
"]",
")",
";",
"while",
"(",
"(",
"$",
"first",
"=",
"reset",
"(",
"$",
"parsedActions",
")",
")",
"&&",
"$",
"first",
"[",
"'isSeparator'",
"]",
")",
"{",
"array_shift",
"(",
"$",
"parsedActions",
")",
";",
"}",
"while",
"(",
"(",
"$",
"last",
"=",
"end",
"(",
"$",
"parsedActions",
")",
")",
"&&",
"$",
"last",
"[",
"'isSeparator'",
"]",
")",
"{",
"array_pop",
"(",
"$",
"parsedActions",
")",
";",
"}",
"return",
"$",
"parsedActions",
";",
"}"
]
| Parse the given UI actions.
@param array $actions Actions to resolve.
@param mixed $renderer Either a {@see ViewableInterface} or TRUE
to determine if any renderables should be processed.
@return array Returns a collection of parsed actions. | [
"Parse",
"the",
"given",
"UI",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L44-L80 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.getActionRenderer | protected function getActionRenderer()
{
$obj = null;
if ($this instanceof FormSidebarInterface) {
if ($this->form()) {
$obj = $this->form()->obj();
}
}
if ($this instanceof ObjectContainerInterface) {
$obj = $this->obj();
}
if ($this instanceof CollectionContainerInterface) {
$obj = isset($this->currentObj) ? $this->currentObj : $this->proto();
}
return $obj instanceof ViewableInterface ? $obj : null;
} | php | protected function getActionRenderer()
{
$obj = null;
if ($this instanceof FormSidebarInterface) {
if ($this->form()) {
$obj = $this->form()->obj();
}
}
if ($this instanceof ObjectContainerInterface) {
$obj = $this->obj();
}
if ($this instanceof CollectionContainerInterface) {
$obj = isset($this->currentObj) ? $this->currentObj : $this->proto();
}
return $obj instanceof ViewableInterface ? $obj : null;
} | [
"protected",
"function",
"getActionRenderer",
"(",
")",
"{",
"$",
"obj",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"instanceof",
"FormSidebarInterface",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"form",
"(",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"form",
"(",
")",
"->",
"obj",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"ObjectContainerInterface",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"obj",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"CollectionContainerInterface",
")",
"{",
"$",
"obj",
"=",
"isset",
"(",
"$",
"this",
"->",
"currentObj",
")",
"?",
"$",
"this",
"->",
"currentObj",
":",
"$",
"this",
"->",
"proto",
"(",
")",
";",
"}",
"return",
"$",
"obj",
"instanceof",
"ViewableInterface",
"?",
"$",
"obj",
":",
"null",
";",
"}"
]
| Fetch a viewable instance to process an action's renderables.
@return ViewableInterface|null | [
"Fetch",
"a",
"viewable",
"instance",
"to",
"process",
"an",
"action",
"s",
"renderables",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L301-L319 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.parseActionCondition | protected function parseActionCondition($condition, $action = null, $renderer = null)
{
unset($action);
if ($renderer === null) {
$renderer = $this->getActionRenderer();
}
if (is_bool($condition)) {
return $condition;
} elseif (is_string($condition)) {
$not = ($condition[0] === '!');
if ($not) {
$condition = ltrim($condition, '!');
}
$result = null;
if ($renderer && is_callable([ $renderer, $condition ])) {
$result = !!$renderer->{$condition}();
} elseif (is_callable([ $this, $condition ])) {
$result = !!$this->{$condition}();
} elseif (is_callable($condition)) {
$result = !!$condition();
} elseif ($renderer) {
$result = !!$renderer->renderTemplate($condition);
}
if ($result !== null) {
return $not ? !$result : $result;
}
}
return $condition;
} | php | protected function parseActionCondition($condition, $action = null, $renderer = null)
{
unset($action);
if ($renderer === null) {
$renderer = $this->getActionRenderer();
}
if (is_bool($condition)) {
return $condition;
} elseif (is_string($condition)) {
$not = ($condition[0] === '!');
if ($not) {
$condition = ltrim($condition, '!');
}
$result = null;
if ($renderer && is_callable([ $renderer, $condition ])) {
$result = !!$renderer->{$condition}();
} elseif (is_callable([ $this, $condition ])) {
$result = !!$this->{$condition}();
} elseif (is_callable($condition)) {
$result = !!$condition();
} elseif ($renderer) {
$result = !!$renderer->renderTemplate($condition);
}
if ($result !== null) {
return $not ? !$result : $result;
}
}
return $condition;
} | [
"protected",
"function",
"parseActionCondition",
"(",
"$",
"condition",
",",
"$",
"action",
"=",
"null",
",",
"$",
"renderer",
"=",
"null",
")",
"{",
"unset",
"(",
"$",
"action",
")",
";",
"if",
"(",
"$",
"renderer",
"===",
"null",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getActionRenderer",
"(",
")",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"condition",
")",
")",
"{",
"return",
"$",
"condition",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"condition",
")",
")",
"{",
"$",
"not",
"=",
"(",
"$",
"condition",
"[",
"0",
"]",
"===",
"'!'",
")",
";",
"if",
"(",
"$",
"not",
")",
"{",
"$",
"condition",
"=",
"ltrim",
"(",
"$",
"condition",
",",
"'!'",
")",
";",
"}",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"renderer",
"&&",
"is_callable",
"(",
"[",
"$",
"renderer",
",",
"$",
"condition",
"]",
")",
")",
"{",
"$",
"result",
"=",
"!",
"!",
"$",
"renderer",
"->",
"{",
"$",
"condition",
"}",
"(",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"[",
"$",
"this",
",",
"$",
"condition",
"]",
")",
")",
"{",
"$",
"result",
"=",
"!",
"!",
"$",
"this",
"->",
"{",
"$",
"condition",
"}",
"(",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"condition",
")",
")",
"{",
"$",
"result",
"=",
"!",
"!",
"$",
"condition",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"renderer",
")",
"{",
"$",
"result",
"=",
"!",
"!",
"$",
"renderer",
"->",
"renderTemplate",
"(",
"$",
"condition",
")",
";",
"}",
"if",
"(",
"$",
"result",
"!==",
"null",
")",
"{",
"return",
"$",
"not",
"?",
"!",
"$",
"result",
":",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"condition",
";",
"}"
]
| Parse the given UI action conditional check.
@param mixed $condition The action's conditional check.
@param mixed $action The action structure.
@param mixed $renderer The renderer.
@return array Resolved action structure. | [
"Parse",
"the",
"given",
"UI",
"action",
"conditional",
"check",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L363-L396 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.parseActionUrl | protected function parseActionUrl($url, $action = null, $renderer = null)
{
unset($action);
if ($renderer === null) {
$renderer = $this->getActionRenderer();
}
if ($url instanceof Translation) {
$url = (string)$url;
}
$url = trim($url);
if (empty($url) && !is_numeric($url)) {
return '#';
}
if ($renderer === null) {
/** @todo Shame! Force `{{ id }}` to use "obj_id" GET parameter… */
$objId = filter_input(INPUT_GET, 'obj_id', FILTER_SANITIZE_STRING);
if ($objId) {
$url = preg_replace('~\{\{\s*(obj_)?id\s*\}\}~', $objId, $url);
}
/** @todo Shame! Force `{{ type }}` to use "obj_type" GET parameter… */
$objType = filter_input(INPUT_GET, 'obj_type', FILTER_SANITIZE_STRING);
if ($objType) {
$url = preg_replace('~\{\{\s*(obj_)?type\s*\}\}~', $objType, $url);
}
if ($url && strpos($url, ':') === false && !in_array($url[0], [ '/', '#', '?' ])) {
$url = $this->adminUrl().$url;
}
return $url;
} elseif ($renderer instanceof ViewableInterface) {
$url = $renderer->renderTemplate($url);
if ($url && strpos($url, ':') === false && !in_array($url[0], [ '/', '#', '?' ])) {
$url = $this->adminUrl().$url;
}
}
return $url;
} | php | protected function parseActionUrl($url, $action = null, $renderer = null)
{
unset($action);
if ($renderer === null) {
$renderer = $this->getActionRenderer();
}
if ($url instanceof Translation) {
$url = (string)$url;
}
$url = trim($url);
if (empty($url) && !is_numeric($url)) {
return '#';
}
if ($renderer === null) {
/** @todo Shame! Force `{{ id }}` to use "obj_id" GET parameter… */
$objId = filter_input(INPUT_GET, 'obj_id', FILTER_SANITIZE_STRING);
if ($objId) {
$url = preg_replace('~\{\{\s*(obj_)?id\s*\}\}~', $objId, $url);
}
/** @todo Shame! Force `{{ type }}` to use "obj_type" GET parameter… */
$objType = filter_input(INPUT_GET, 'obj_type', FILTER_SANITIZE_STRING);
if ($objType) {
$url = preg_replace('~\{\{\s*(obj_)?type\s*\}\}~', $objType, $url);
}
if ($url && strpos($url, ':') === false && !in_array($url[0], [ '/', '#', '?' ])) {
$url = $this->adminUrl().$url;
}
return $url;
} elseif ($renderer instanceof ViewableInterface) {
$url = $renderer->renderTemplate($url);
if ($url && strpos($url, ':') === false && !in_array($url[0], [ '/', '#', '?' ])) {
$url = $this->adminUrl().$url;
}
}
return $url;
} | [
"protected",
"function",
"parseActionUrl",
"(",
"$",
"url",
",",
"$",
"action",
"=",
"null",
",",
"$",
"renderer",
"=",
"null",
")",
"{",
"unset",
"(",
"$",
"action",
")",
";",
"if",
"(",
"$",
"renderer",
"===",
"null",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getActionRenderer",
"(",
")",
";",
"}",
"if",
"(",
"$",
"url",
"instanceof",
"Translation",
")",
"{",
"$",
"url",
"=",
"(",
"string",
")",
"$",
"url",
";",
"}",
"$",
"url",
"=",
"trim",
"(",
"$",
"url",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"url",
")",
")",
"{",
"return",
"'#'",
";",
"}",
"if",
"(",
"$",
"renderer",
"===",
"null",
")",
"{",
"/** @todo Shame! Force `{{ id }}` to use \"obj_id\" GET parameter… */",
"$",
"objId",
"=",
"filter_input",
"(",
"INPUT_GET",
",",
"'obj_id'",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"if",
"(",
"$",
"objId",
")",
"{",
"$",
"url",
"=",
"preg_replace",
"(",
"'~\\{\\{\\s*(obj_)?id\\s*\\}\\}~'",
",",
"$",
"objId",
",",
"$",
"url",
")",
";",
"}",
"/** @todo Shame! Force `{{ type }}` to use \"obj_type\" GET parameter… */",
"$",
"objType",
"=",
"filter_input",
"(",
"INPUT_GET",
",",
"'obj_type'",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"if",
"(",
"$",
"objType",
")",
"{",
"$",
"url",
"=",
"preg_replace",
"(",
"'~\\{\\{\\s*(obj_)?type\\s*\\}\\}~'",
",",
"$",
"objType",
",",
"$",
"url",
")",
";",
"}",
"if",
"(",
"$",
"url",
"&&",
"strpos",
"(",
"$",
"url",
",",
"':'",
")",
"===",
"false",
"&&",
"!",
"in_array",
"(",
"$",
"url",
"[",
"0",
"]",
",",
"[",
"'/'",
",",
"'#'",
",",
"'?'",
"]",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"adminUrl",
"(",
")",
".",
"$",
"url",
";",
"}",
"return",
"$",
"url",
";",
"}",
"elseif",
"(",
"$",
"renderer",
"instanceof",
"ViewableInterface",
")",
"{",
"$",
"url",
"=",
"$",
"renderer",
"->",
"renderTemplate",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"url",
"&&",
"strpos",
"(",
"$",
"url",
",",
"':'",
")",
"===",
"false",
"&&",
"!",
"in_array",
"(",
"$",
"url",
"[",
"0",
"]",
",",
"[",
"'/'",
",",
"'#'",
",",
"'?'",
"]",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"adminUrl",
"(",
")",
".",
"$",
"url",
";",
"}",
"}",
"return",
"$",
"url",
";",
"}"
]
| Parse the given UI action URL.
@param string $url The action's URL.
@param mixed $action The action structure.
@param mixed $renderer The renderer.
@return array Resolved action structure. | [
"Parse",
"the",
"given",
"UI",
"action",
"URL",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L406-L451 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.parseActionCssClasses | protected function parseActionCssClasses($classes, $action = null, $renderer = null)
{
if ($renderer === null) {
$renderer = $this->getActionRenderer();
}
if (is_string($classes)) {
$classes = explode(' ', $classes);
} elseif (!is_array($classes)) {
$classes = [];
}
$classes[] = 'btn';
$classes[] = 'btn-'.$action['actionType'];
$classes[] = $this->jsActionPrefix().'-'.$action['ident'];
return $classes;
} | php | protected function parseActionCssClasses($classes, $action = null, $renderer = null)
{
if ($renderer === null) {
$renderer = $this->getActionRenderer();
}
if (is_string($classes)) {
$classes = explode(' ', $classes);
} elseif (!is_array($classes)) {
$classes = [];
}
$classes[] = 'btn';
$classes[] = 'btn-'.$action['actionType'];
$classes[] = $this->jsActionPrefix().'-'.$action['ident'];
return $classes;
} | [
"protected",
"function",
"parseActionCssClasses",
"(",
"$",
"classes",
",",
"$",
"action",
"=",
"null",
",",
"$",
"renderer",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"renderer",
"===",
"null",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getActionRenderer",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"classes",
")",
")",
"{",
"$",
"classes",
"=",
"explode",
"(",
"' '",
",",
"$",
"classes",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"classes",
")",
")",
"{",
"$",
"classes",
"=",
"[",
"]",
";",
"}",
"$",
"classes",
"[",
"]",
"=",
"'btn'",
";",
"$",
"classes",
"[",
"]",
"=",
"'btn-'",
".",
"$",
"action",
"[",
"'actionType'",
"]",
";",
"$",
"classes",
"[",
"]",
"=",
"$",
"this",
"->",
"jsActionPrefix",
"(",
")",
".",
"'-'",
".",
"$",
"action",
"[",
"'ident'",
"]",
";",
"return",
"$",
"classes",
";",
"}"
]
| Parse the given UI action CSS classes.
@param mixed $classes The action's CSS classes.
@param mixed $action The action structure.
@param mixed $renderer The renderer.
@return array | [
"Parse",
"the",
"given",
"UI",
"action",
"CSS",
"classes",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L461-L477 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.defaultActionStruct | protected function defaultActionStruct()
{
return [
'ident' => null,
'priority' => null,
'permissions' => [],
'condition' => null,
'active' => true,
'empty' => false,
'label' => null,
'showLabel' => true,
'icon' => null,
'url' => null,
'name' => null,
'value' => null,
'target' => null,
'isText' => false,
'isLink' => false,
'isButton' => true,
'isHeader' => false,
'isSubmittable' => false,
'isSeparator' => false,
'cssClasses' => null,
'actionType' => 'dark',
'buttonType' => 'button',
'splitButton' => false,
'hasActions' => false,
'actions' => [],
];
} | php | protected function defaultActionStruct()
{
return [
'ident' => null,
'priority' => null,
'permissions' => [],
'condition' => null,
'active' => true,
'empty' => false,
'label' => null,
'showLabel' => true,
'icon' => null,
'url' => null,
'name' => null,
'value' => null,
'target' => null,
'isText' => false,
'isLink' => false,
'isButton' => true,
'isHeader' => false,
'isSubmittable' => false,
'isSeparator' => false,
'cssClasses' => null,
'actionType' => 'dark',
'buttonType' => 'button',
'splitButton' => false,
'hasActions' => false,
'actions' => [],
];
} | [
"protected",
"function",
"defaultActionStruct",
"(",
")",
"{",
"return",
"[",
"'ident'",
"=>",
"null",
",",
"'priority'",
"=>",
"null",
",",
"'permissions'",
"=>",
"[",
"]",
",",
"'condition'",
"=>",
"null",
",",
"'active'",
"=>",
"true",
",",
"'empty'",
"=>",
"false",
",",
"'label'",
"=>",
"null",
",",
"'showLabel'",
"=>",
"true",
",",
"'icon'",
"=>",
"null",
",",
"'url'",
"=>",
"null",
",",
"'name'",
"=>",
"null",
",",
"'value'",
"=>",
"null",
",",
"'target'",
"=>",
"null",
",",
"'isText'",
"=>",
"false",
",",
"'isLink'",
"=>",
"false",
",",
"'isButton'",
"=>",
"true",
",",
"'isHeader'",
"=>",
"false",
",",
"'isSubmittable'",
"=>",
"false",
",",
"'isSeparator'",
"=>",
"false",
",",
"'cssClasses'",
"=>",
"null",
",",
"'actionType'",
"=>",
"'dark'",
",",
"'buttonType'",
"=>",
"'button'",
",",
"'splitButton'",
"=>",
"false",
",",
"'hasActions'",
"=>",
"false",
",",
"'actions'",
"=>",
"[",
"]",
",",
"]",
";",
"}"
]
| Retrieve the default action structure.
@return array | [
"Retrieve",
"the",
"default",
"action",
"structure",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L484-L513 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ActionContainerTrait.php | ActionContainerTrait.compareActions | protected function compareActions(array $a, array $b)
{
$a = isset($a['priority']) ? $a['priority'] : 0;
$b = isset($b['priority']) ? $b['priority'] : 0;
$c = isset($action['isSubmittable']) && $action['isSubmittable'];
return ($c || ($a === 0) || ($a >= $b));
} | php | protected function compareActions(array $a, array $b)
{
$a = isset($a['priority']) ? $a['priority'] : 0;
$b = isset($b['priority']) ? $b['priority'] : 0;
$c = isset($action['isSubmittable']) && $action['isSubmittable'];
return ($c || ($a === 0) || ($a >= $b));
} | [
"protected",
"function",
"compareActions",
"(",
"array",
"$",
"a",
",",
"array",
"$",
"b",
")",
"{",
"$",
"a",
"=",
"isset",
"(",
"$",
"a",
"[",
"'priority'",
"]",
")",
"?",
"$",
"a",
"[",
"'priority'",
"]",
":",
"0",
";",
"$",
"b",
"=",
"isset",
"(",
"$",
"b",
"[",
"'priority'",
"]",
")",
"?",
"$",
"b",
"[",
"'priority'",
"]",
":",
"0",
";",
"$",
"c",
"=",
"isset",
"(",
"$",
"action",
"[",
"'isSubmittable'",
"]",
")",
"&&",
"$",
"action",
"[",
"'isSubmittable'",
"]",
";",
"return",
"(",
"$",
"c",
"||",
"(",
"$",
"a",
"===",
"0",
")",
"||",
"(",
"$",
"a",
">=",
"$",
"b",
")",
")",
";",
"}"
]
| To be called when merging actions.
Note: Practical for extended classes.
@param array $a First action object to sort.
@param array $b Second action object to sort.
@return boolean Returns TRUE if $a has priority. Otherwise, FALSE for $b. | [
"To",
"be",
"called",
"when",
"merging",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ActionContainerTrait.php#L552-L559 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Config.php | Config.defaults | public function defaults()
{
$baseDir = rtrim(realpath(__DIR__.'/../../../'), '/');
$confDir = $baseDir.'/config';
return $this->loadFile($confDir.'/admin.config.default.json');
} | php | public function defaults()
{
$baseDir = rtrim(realpath(__DIR__.'/../../../'), '/');
$confDir = $baseDir.'/config';
return $this->loadFile($confDir.'/admin.config.default.json');
} | [
"public",
"function",
"defaults",
"(",
")",
"{",
"$",
"baseDir",
"=",
"rtrim",
"(",
"realpath",
"(",
"__DIR__",
".",
"'/../../../'",
")",
",",
"'/'",
")",
";",
"$",
"confDir",
"=",
"$",
"baseDir",
".",
"'/config'",
";",
"return",
"$",
"this",
"->",
"loadFile",
"(",
"$",
"confDir",
".",
"'/admin.config.default.json'",
")",
";",
"}"
]
| The default data is defined in a JSON file.
@return array | [
"The",
"default",
"data",
"is",
"defined",
"in",
"a",
"JSON",
"file",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Config.php#L48-L54 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Config.php | Config.setBasePath | public function setBasePath($path)
{
if (!is_string($path)) {
throw new InvalidArgumentException(
'Path must be a string'
);
}
// Can not be empty
if ($path == '') {
throw new InvalidArgumentException(
'Path can not be empty'
);
}
$this->basePath = $path;
return $this;
} | php | public function setBasePath($path)
{
if (!is_string($path)) {
throw new InvalidArgumentException(
'Path must be a string'
);
}
// Can not be empty
if ($path == '') {
throw new InvalidArgumentException(
'Path can not be empty'
);
}
$this->basePath = $path;
return $this;
} | [
"public",
"function",
"setBasePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Path must be a string'",
")",
";",
"}",
"// Can not be empty",
"if",
"(",
"$",
"path",
"==",
"''",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Path can not be empty'",
")",
";",
"}",
"$",
"this",
"->",
"basePath",
"=",
"$",
"path",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the admin module's route group.
@param string $path The admin module base path.
@throws InvalidArgumentException If the route group is invalid.
@return self | [
"Set",
"the",
"admin",
"module",
"s",
"route",
"group",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Config.php#L63-L80 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Config.php | Config.setRoutes | public function setRoutes(array $routes)
{
$toIterate = RouteConfig::defaultRouteTypes();
foreach ($routes as $key => $val) {
if (in_array($key, $toIterate) && isset($this->routes[$key])) {
$this->routes[$key] = array_merge($this->routes[$key], $val);
} else {
$this->routes[$key] = $val;
}
}
return $this;
} | php | public function setRoutes(array $routes)
{
$toIterate = RouteConfig::defaultRouteTypes();
foreach ($routes as $key => $val) {
if (in_array($key, $toIterate) && isset($this->routes[$key])) {
$this->routes[$key] = array_merge($this->routes[$key], $val);
} else {
$this->routes[$key] = $val;
}
}
return $this;
} | [
"public",
"function",
"setRoutes",
"(",
"array",
"$",
"routes",
")",
"{",
"$",
"toIterate",
"=",
"RouteConfig",
"::",
"defaultRouteTypes",
"(",
")",
";",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"toIterate",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"key",
"]",
",",
"$",
"val",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"routes",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Parse the admin module's route configuration.
@see \Charcoal\App\AppConfig::setRoutes() For a similar implementation.
@param array $routes The route configuration structure to set.
@return self | [
"Parse",
"the",
"admin",
"module",
"s",
"route",
"configuration",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Config.php#L99-L111 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Config.php | Config.setHandlers | public function setHandlers(array $handlers)
{
$this->handlers = array_fill_keys(HandlerConfig::defaultHandlerTypes(), []);
$this->handlers['defaults'] = [];
foreach ($handlers as $handler => $data) {
$this->handlers[$handler] = array_replace(
$this->handlers[$handler],
$data
);
}
return $this;
} | php | public function setHandlers(array $handlers)
{
$this->handlers = array_fill_keys(HandlerConfig::defaultHandlerTypes(), []);
$this->handlers['defaults'] = [];
foreach ($handlers as $handler => $data) {
$this->handlers[$handler] = array_replace(
$this->handlers[$handler],
$data
);
}
return $this;
} | [
"public",
"function",
"setHandlers",
"(",
"array",
"$",
"handlers",
")",
"{",
"$",
"this",
"->",
"handlers",
"=",
"array_fill_keys",
"(",
"HandlerConfig",
"::",
"defaultHandlerTypes",
"(",
")",
",",
"[",
"]",
")",
";",
"$",
"this",
"->",
"handlers",
"[",
"'defaults'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
"=>",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"handlers",
"[",
"$",
"handler",
"]",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"handler",
"]",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Define custom response and error handlers.
Charcoal overrides four of Slim's standard handlers:
- "notFoundHandler"
- "notAllowedHandler"
- "errorHandler"
- "phpErrorHandler"
@param array $handlers The handlers configuration structure to set.
@return self | [
"Define",
"custom",
"response",
"and",
"error",
"handlers",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Config.php#L126-L139 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/MapWidget.php | MapWidget.setLat | public function setLat($coord)
{
if ($coord === null) {
$this->lat = $coord;
return $this;
}
if (!is_numeric($coord)) {
throw new InvalidArgumentException(
'The "lat" must be a number'
);
}
$this->lat = (float)$coord;
return $this;
} | php | public function setLat($coord)
{
if ($coord === null) {
$this->lat = $coord;
return $this;
}
if (!is_numeric($coord)) {
throw new InvalidArgumentException(
'The "lat" must be a number'
);
}
$this->lat = (float)$coord;
return $this;
} | [
"public",
"function",
"setLat",
"(",
"$",
"coord",
")",
"{",
"if",
"(",
"$",
"coord",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"lat",
"=",
"$",
"coord",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"coord",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The \"lat\" must be a number'",
")",
";",
"}",
"$",
"this",
"->",
"lat",
"=",
"(",
"float",
")",
"$",
"coord",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the latitude for the widget.
@param float $coord The latitude of a location.
@throws InvalidArgumentException If the longitude is not a number.
@return self | [
"Set",
"the",
"latitude",
"for",
"the",
"widget",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/MapWidget.php#L182-L198 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/MapWidget.php | MapWidget.lat | public function lat()
{
if ($this->lat !== null) {
return $this->lat;
}
if (!$this->hasObj() || !$this->latProperty()) {
return null;
}
return $this->obj()[$this->latProperty()];
} | php | public function lat()
{
if ($this->lat !== null) {
return $this->lat;
}
if (!$this->hasObj() || !$this->latProperty()) {
return null;
}
return $this->obj()[$this->latProperty()];
} | [
"public",
"function",
"lat",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lat",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"lat",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasObj",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"latProperty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"obj",
"(",
")",
"[",
"$",
"this",
"->",
"latProperty",
"(",
")",
"]",
";",
"}"
]
| Retrieve the latitude from the object's latitude property.
@return float|null | [
"Retrieve",
"the",
"latitude",
"from",
"the",
"object",
"s",
"latitude",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/MapWidget.php#L205-L216 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/MapWidget.php | MapWidget.setLng | public function setLng($coord)
{
if ($coord === null) {
$this->lng = $coord;
return $this;
}
if (!is_numeric($coord)) {
throw new InvalidArgumentException(
'The "lng" must be a number'
);
}
$this->lng = (float)$coord;
return $this;
} | php | public function setLng($coord)
{
if ($coord === null) {
$this->lng = $coord;
return $this;
}
if (!is_numeric($coord)) {
throw new InvalidArgumentException(
'The "lng" must be a number'
);
}
$this->lng = (float)$coord;
return $this;
} | [
"public",
"function",
"setLng",
"(",
"$",
"coord",
")",
"{",
"if",
"(",
"$",
"coord",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"lng",
"=",
"$",
"coord",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"coord",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The \"lng\" must be a number'",
")",
";",
"}",
"$",
"this",
"->",
"lng",
"=",
"(",
"float",
")",
"$",
"coord",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the longitude of the object's geolocation.
@param float $coord The longitude of a location.
@throws InvalidArgumentException If the longitude is not a number.
@return self | [
"Set",
"the",
"longitude",
"of",
"the",
"object",
"s",
"geolocation",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/MapWidget.php#L225-L241 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/MapWidget.php | MapWidget.lng | public function lng()
{
if ($this->lng !== null) {
return $this->lng;
}
if (!$this->hasObj() || !$this->lngProperty()) {
return null;
}
return $this->obj()[$this->lngProperty()];
} | php | public function lng()
{
if ($this->lng !== null) {
return $this->lng;
}
if (!$this->hasObj() || !$this->lngProperty()) {
return null;
}
return $this->obj()[$this->lngProperty()];
} | [
"public",
"function",
"lng",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lng",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"lng",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasObj",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"lngProperty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"obj",
"(",
")",
"[",
"$",
"this",
"->",
"lngProperty",
"(",
")",
"]",
";",
"}"
]
| Retrieve the longitude from the object's longitude property.
@return float|null | [
"Retrieve",
"the",
"longitude",
"from",
"the",
"object",
"s",
"longitude",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/MapWidget.php#L248-L259 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/MapWidget.php | MapWidget.hasObj | public function hasObj()
{
if ($this->obj === null) {
try {
$this->obj();
} catch (InvalidArgumentException $e) {
return false;
}
}
return !empty($this->obj);
} | php | public function hasObj()
{
if ($this->obj === null) {
try {
$this->obj();
} catch (InvalidArgumentException $e) {
return false;
}
}
return !empty($this->obj);
} | [
"public",
"function",
"hasObj",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"obj",
"===",
"null",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"obj",
"(",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"obj",
")",
";",
"}"
]
| Determine if the widget has a related object.
@return boolean | [
"Determine",
"if",
"the",
"widget",
"has",
"a",
"related",
"object",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/MapWidget.php#L315-L326 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/MapWidget.php | MapWidget.obj | public function obj()
{
if ($this->obj === null) {
$objId = filter_input(INPUT_GET, 'obj_id', FILTER_SANITIZE_STRING);
$objType = filter_input(INPUT_GET, 'obj_type', FILTER_SANITIZE_STRING);
if ($objId && $objType) {
$obj = $this->modelFactory()->create($objType);
$obj->load($objId);
$this->obj = $obj;
} else {
throw new InvalidArgumentException('Missing Object Type or ID');
}
}
return $this->obj;
} | php | public function obj()
{
if ($this->obj === null) {
$objId = filter_input(INPUT_GET, 'obj_id', FILTER_SANITIZE_STRING);
$objType = filter_input(INPUT_GET, 'obj_type', FILTER_SANITIZE_STRING);
if ($objId && $objType) {
$obj = $this->modelFactory()->create($objType);
$obj->load($objId);
$this->obj = $obj;
} else {
throw new InvalidArgumentException('Missing Object Type or ID');
}
}
return $this->obj;
} | [
"public",
"function",
"obj",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"obj",
"===",
"null",
")",
"{",
"$",
"objId",
"=",
"filter_input",
"(",
"INPUT_GET",
",",
"'obj_id'",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"$",
"objType",
"=",
"filter_input",
"(",
"INPUT_GET",
",",
"'obj_type'",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"if",
"(",
"$",
"objId",
"&&",
"$",
"objType",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"modelFactory",
"(",
")",
"->",
"create",
"(",
"$",
"objType",
")",
";",
"$",
"obj",
"->",
"load",
"(",
"$",
"objId",
")",
";",
"$",
"this",
"->",
"obj",
"=",
"$",
"obj",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Missing Object Type or ID'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"obj",
";",
"}"
]
| Retrieve the widget's related object.
@throws InvalidArgumentException If the object type or ID are invalid or missing.
@return ModelInterface | [
"Retrieve",
"the",
"widget",
"s",
"related",
"object",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/MapWidget.php#L334-L350 | train |
acquia/commerce-manager | modules/acm/src/Element/AcmPasswordUpdate.php | AcmPasswordUpdate.processPasswordUpdate | public static function processPasswordUpdate(&$element, FormStateInterface $form_state, &$complete_form) {
$element['oldpass'] = [
'#type' => 'password',
'#title' => t('Old Password'),
'#value' => empty($element['#value']) ? NULL : $element['#value']['oldpass'],
'#required' => $element['#required'],
'#error_no_message' => TRUE,
];
$element['pass1'] = [
'#type' => 'password',
'#title' => t('Password'),
'#value' => empty($element['#value']) ? NULL : $element['#value']['pass1'],
'#required' => $element['#required'],
'#attributes' => ['class' => ['password-field', 'js-password-field']],
'#error_no_message' => TRUE,
];
$element['pass2'] = [
'#type' => 'password',
'#title' => t('Confirm password'),
'#value' => empty($element['#value']) ? NULL : $element['#value']['pass2'],
'#required' => $element['#required'],
'#attributes' => ['class' => ['password-confirm', 'js-password-confirm']],
'#error_no_message' => TRUE,
];
$element['#element_validate'] = [[get_called_class(), 'validatePasswordUpdate']];
$element['#tree'] = TRUE;
if (isset($element['#size'])) {
$element['pass1']['#size'] = $element['pass2']['#size'] + $element['oldpass']['#size'] = $element['#size'];
}
return $element;
} | php | public static function processPasswordUpdate(&$element, FormStateInterface $form_state, &$complete_form) {
$element['oldpass'] = [
'#type' => 'password',
'#title' => t('Old Password'),
'#value' => empty($element['#value']) ? NULL : $element['#value']['oldpass'],
'#required' => $element['#required'],
'#error_no_message' => TRUE,
];
$element['pass1'] = [
'#type' => 'password',
'#title' => t('Password'),
'#value' => empty($element['#value']) ? NULL : $element['#value']['pass1'],
'#required' => $element['#required'],
'#attributes' => ['class' => ['password-field', 'js-password-field']],
'#error_no_message' => TRUE,
];
$element['pass2'] = [
'#type' => 'password',
'#title' => t('Confirm password'),
'#value' => empty($element['#value']) ? NULL : $element['#value']['pass2'],
'#required' => $element['#required'],
'#attributes' => ['class' => ['password-confirm', 'js-password-confirm']],
'#error_no_message' => TRUE,
];
$element['#element_validate'] = [[get_called_class(), 'validatePasswordUpdate']];
$element['#tree'] = TRUE;
if (isset($element['#size'])) {
$element['pass1']['#size'] = $element['pass2']['#size'] + $element['oldpass']['#size'] = $element['#size'];
}
return $element;
} | [
"public",
"static",
"function",
"processPasswordUpdate",
"(",
"&",
"$",
"element",
",",
"FormStateInterface",
"$",
"form_state",
",",
"&",
"$",
"complete_form",
")",
"{",
"$",
"element",
"[",
"'oldpass'",
"]",
"=",
"[",
"'#type'",
"=>",
"'password'",
",",
"'#title'",
"=>",
"t",
"(",
"'Old Password'",
")",
",",
"'#value'",
"=>",
"empty",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
"?",
"NULL",
":",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'oldpass'",
"]",
",",
"'#required'",
"=>",
"$",
"element",
"[",
"'#required'",
"]",
",",
"'#error_no_message'",
"=>",
"TRUE",
",",
"]",
";",
"$",
"element",
"[",
"'pass1'",
"]",
"=",
"[",
"'#type'",
"=>",
"'password'",
",",
"'#title'",
"=>",
"t",
"(",
"'Password'",
")",
",",
"'#value'",
"=>",
"empty",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
"?",
"NULL",
":",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'pass1'",
"]",
",",
"'#required'",
"=>",
"$",
"element",
"[",
"'#required'",
"]",
",",
"'#attributes'",
"=>",
"[",
"'class'",
"=>",
"[",
"'password-field'",
",",
"'js-password-field'",
"]",
"]",
",",
"'#error_no_message'",
"=>",
"TRUE",
",",
"]",
";",
"$",
"element",
"[",
"'pass2'",
"]",
"=",
"[",
"'#type'",
"=>",
"'password'",
",",
"'#title'",
"=>",
"t",
"(",
"'Confirm password'",
")",
",",
"'#value'",
"=>",
"empty",
"(",
"$",
"element",
"[",
"'#value'",
"]",
")",
"?",
"NULL",
":",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'pass2'",
"]",
",",
"'#required'",
"=>",
"$",
"element",
"[",
"'#required'",
"]",
",",
"'#attributes'",
"=>",
"[",
"'class'",
"=>",
"[",
"'password-confirm'",
",",
"'js-password-confirm'",
"]",
"]",
",",
"'#error_no_message'",
"=>",
"TRUE",
",",
"]",
";",
"$",
"element",
"[",
"'#element_validate'",
"]",
"=",
"[",
"[",
"get_called_class",
"(",
")",
",",
"'validatePasswordUpdate'",
"]",
"]",
";",
"$",
"element",
"[",
"'#tree'",
"]",
"=",
"TRUE",
";",
"if",
"(",
"isset",
"(",
"$",
"element",
"[",
"'#size'",
"]",
")",
")",
"{",
"$",
"element",
"[",
"'pass1'",
"]",
"[",
"'#size'",
"]",
"=",
"$",
"element",
"[",
"'pass2'",
"]",
"[",
"'#size'",
"]",
"+",
"$",
"element",
"[",
"'oldpass'",
"]",
"[",
"'#size'",
"]",
"=",
"$",
"element",
"[",
"'#size'",
"]",
";",
"}",
"return",
"$",
"element",
";",
"}"
]
| Expand an acm_password_update field into three text boxes. | [
"Expand",
"an",
"acm_password_update",
"field",
"into",
"three",
"text",
"boxes",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Element/AcmPasswordUpdate.php#L75-L107 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormGroupWidget.php | FormGroupWidget.languages | public function languages()
{
$currentLocale = $this->translator()->getLocale();
$languages = [];
foreach ($this->translator()->locales() as $locale => $localeStruct) {
/**
* @see \Charcoal\Admin\Widget\FormSidebarWidget::languages()
* @see \Charcoal\Property\LangProperty::localeChoices()
*/
if (isset($localeStruct['name'])) {
$label = $this->translator()->translation($localeStruct['name']);
} else {
$trans = 'locale.'.$locale;
if ($trans === $this->translator()->translate($trans)) {
$label = strtoupper($locale);
} else {
$label = $this->translator()->translation($trans);
}
}
$languages[] = [
'ident' => $locale,
'name' => $this->translator()->translation($label),
'current' => ($locale === $currentLocale)
];
}
return $languages;
} | php | public function languages()
{
$currentLocale = $this->translator()->getLocale();
$languages = [];
foreach ($this->translator()->locales() as $locale => $localeStruct) {
/**
* @see \Charcoal\Admin\Widget\FormSidebarWidget::languages()
* @see \Charcoal\Property\LangProperty::localeChoices()
*/
if (isset($localeStruct['name'])) {
$label = $this->translator()->translation($localeStruct['name']);
} else {
$trans = 'locale.'.$locale;
if ($trans === $this->translator()->translate($trans)) {
$label = strtoupper($locale);
} else {
$label = $this->translator()->translation($trans);
}
}
$languages[] = [
'ident' => $locale,
'name' => $this->translator()->translation($label),
'current' => ($locale === $currentLocale)
];
}
return $languages;
} | [
"public",
"function",
"languages",
"(",
")",
"{",
"$",
"currentLocale",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"languages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"locales",
"(",
")",
"as",
"$",
"locale",
"=>",
"$",
"localeStruct",
")",
"{",
"/**\n * @see \\Charcoal\\Admin\\Widget\\FormSidebarWidget::languages()\n * @see \\Charcoal\\Property\\LangProperty::localeChoices()\n */",
"if",
"(",
"isset",
"(",
"$",
"localeStruct",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"localeStruct",
"[",
"'name'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"trans",
"=",
"'locale.'",
".",
"$",
"locale",
";",
"if",
"(",
"$",
"trans",
"===",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translate",
"(",
"$",
"trans",
")",
")",
"{",
"$",
"label",
"=",
"strtoupper",
"(",
"$",
"locale",
")",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"trans",
")",
";",
"}",
"}",
"$",
"languages",
"[",
"]",
"=",
"[",
"'ident'",
"=>",
"$",
"locale",
",",
"'name'",
"=>",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"label",
")",
",",
"'current'",
"=>",
"(",
"$",
"locale",
"===",
"$",
"currentLocale",
")",
"]",
";",
"}",
"return",
"$",
"languages",
";",
"}"
]
| Retrieve the available languages, formatted for the sidebar language-switcher.
@see FormSidebarWidget::languages()
@return array | [
"Retrieve",
"the",
"available",
"languages",
"formatted",
"for",
"the",
"sidebar",
"language",
"-",
"switcher",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroupWidget.php#L231-L259 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/Object/AbstractSaveAction.php | AbstractSaveAction.addFeedbackFromValidation | public function addFeedbackFromValidation(ModelInterface $obj, $filters = null)
{
$validator = $obj->validator();
$levels = [ ModelValidator::ERROR, ModelValidator::WARNING, ModelValidator::NOTICE ];
if (is_string($filters) && in_array($filters, $levels)) {
$results = call_user_func([ $validator, $filters.'Results' ]);
foreach ($results as $result) {
$this->addFeedback($result->level(), $result->message());
}
return $this;
}
if (!is_array($filters) && $filters !== null) {
throw new InvalidArgumentException(
'Filters must be an array of validation levels or NULL'
);
}
$validation = $validator->results();
foreach ($validation as $level => $results) {
if ($filters === null || in_array($level, $filters)) {
foreach ($results as $result) {
$this->addFeedback($result->level(), $result->message());
}
}
}
return $this;
} | php | public function addFeedbackFromValidation(ModelInterface $obj, $filters = null)
{
$validator = $obj->validator();
$levels = [ ModelValidator::ERROR, ModelValidator::WARNING, ModelValidator::NOTICE ];
if (is_string($filters) && in_array($filters, $levels)) {
$results = call_user_func([ $validator, $filters.'Results' ]);
foreach ($results as $result) {
$this->addFeedback($result->level(), $result->message());
}
return $this;
}
if (!is_array($filters) && $filters !== null) {
throw new InvalidArgumentException(
'Filters must be an array of validation levels or NULL'
);
}
$validation = $validator->results();
foreach ($validation as $level => $results) {
if ($filters === null || in_array($level, $filters)) {
foreach ($results as $result) {
$this->addFeedback($result->level(), $result->message());
}
}
}
return $this;
} | [
"public",
"function",
"addFeedbackFromValidation",
"(",
"ModelInterface",
"$",
"obj",
",",
"$",
"filters",
"=",
"null",
")",
"{",
"$",
"validator",
"=",
"$",
"obj",
"->",
"validator",
"(",
")",
";",
"$",
"levels",
"=",
"[",
"ModelValidator",
"::",
"ERROR",
",",
"ModelValidator",
"::",
"WARNING",
",",
"ModelValidator",
"::",
"NOTICE",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"filters",
")",
"&&",
"in_array",
"(",
"$",
"filters",
",",
"$",
"levels",
")",
")",
"{",
"$",
"results",
"=",
"call_user_func",
"(",
"[",
"$",
"validator",
",",
"$",
"filters",
".",
"'Results'",
"]",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"addFeedback",
"(",
"$",
"result",
"->",
"level",
"(",
")",
",",
"$",
"result",
"->",
"message",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"filters",
")",
"&&",
"$",
"filters",
"!==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Filters must be an array of validation levels or NULL'",
")",
";",
"}",
"$",
"validation",
"=",
"$",
"validator",
"->",
"results",
"(",
")",
";",
"foreach",
"(",
"$",
"validation",
"as",
"$",
"level",
"=>",
"$",
"results",
")",
"{",
"if",
"(",
"$",
"filters",
"===",
"null",
"||",
"in_array",
"(",
"$",
"level",
",",
"$",
"filters",
")",
")",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"addFeedback",
"(",
"$",
"result",
"->",
"level",
"(",
")",
",",
"$",
"result",
"->",
"message",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Merge the given object's validation results the response feedback.
@param ModelInterface $obj The validated object.
@param string[]|string|null $filters Filter the levels to merge.
@throws InvalidArgumentException If the filters are invalid.
@return SaveAction Chainable | [
"Merge",
"the",
"given",
"object",
"s",
"validation",
"results",
"the",
"response",
"feedback",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Object/AbstractSaveAction.php#L66-L96 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/NestedWidgetInput.php | NestedWidgetInput.formGroupFactory | protected function formGroupFactory()
{
if ($this->formGroupFactory === null) {
throw new RuntimeException(sprintf(
'Form Group Factory is not defined for "%s"',
get_class($this)
));
}
return $this->formGroupFactory;
} | php | protected function formGroupFactory()
{
if ($this->formGroupFactory === null) {
throw new RuntimeException(sprintf(
'Form Group Factory is not defined for "%s"',
get_class($this)
));
}
return $this->formGroupFactory;
} | [
"protected",
"function",
"formGroupFactory",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"formGroupFactory",
"===",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Form Group Factory is not defined for \"%s\"'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formGroupFactory",
";",
"}"
]
| Retrieve the form group factory.
@throws RuntimeException If the form group factory was not previously set.
@return FactoryInterface | [
"Retrieve",
"the",
"form",
"group",
"factory",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/NestedWidgetInput.php#L148-L158 | train |
dazzle-php/ssh | src/SSH/Driver/Sftp.php | Sftp.handleHeartbeat | public function handleHeartbeat()
{
$fp = @fopen("ssh2.sftp://" . $this->resource . "/.", "r");
if (!$fp || !is_resource($fp))
{
return $this->ssh2->disconnect();
}
fclose($fp);
$this->handleData();
} | php | public function handleHeartbeat()
{
$fp = @fopen("ssh2.sftp://" . $this->resource . "/.", "r");
if (!$fp || !is_resource($fp))
{
return $this->ssh2->disconnect();
}
fclose($fp);
$this->handleData();
} | [
"public",
"function",
"handleHeartbeat",
"(",
")",
"{",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"\"ssh2.sftp://\"",
".",
"$",
"this",
"->",
"resource",
".",
"\"/.\"",
",",
"\"r\"",
")",
";",
"if",
"(",
"!",
"$",
"fp",
"||",
"!",
"is_resource",
"(",
"$",
"fp",
")",
")",
"{",
"return",
"$",
"this",
"->",
"ssh2",
"->",
"disconnect",
"(",
")",
";",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"$",
"this",
"->",
"handleData",
"(",
")",
";",
"}"
]
| Determine whether connection is still open.
@internal | [
"Determine",
"whether",
"connection",
"is",
"still",
"open",
"."
]
| 8e48867f7b147a7b27bd4e995ac42e6df65c17bb | https://github.com/dazzle-php/ssh/blob/8e48867f7b147a7b27bd4e995ac42e6df65c17bb/src/SSH/Driver/Sftp.php#L260-L272 | train |
dazzle-php/ssh | src/SSH/Driver/Sftp.php | Sftp.handleData | public function handleData()
{
if ($this->paused || $this->resourcesCounter === 0)
{
return;
}
// handle all reading
foreach ($this->resources as $resource)
{
if (!$resource->isPaused() && $resource->isReadable())
{
$resource->handleRead();
}
}
// handle all writing
foreach ($this->resources as $resource)
{
if (!$resource->isPaused() && $resource->isWritable())
{
$resource->handleWrite();
}
}
} | php | public function handleData()
{
if ($this->paused || $this->resourcesCounter === 0)
{
return;
}
// handle all reading
foreach ($this->resources as $resource)
{
if (!$resource->isPaused() && $resource->isReadable())
{
$resource->handleRead();
}
}
// handle all writing
foreach ($this->resources as $resource)
{
if (!$resource->isPaused() && $resource->isWritable())
{
$resource->handleWrite();
}
}
} | [
"public",
"function",
"handleData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"paused",
"||",
"$",
"this",
"->",
"resourcesCounter",
"===",
"0",
")",
"{",
"return",
";",
"}",
"// handle all reading",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"!",
"$",
"resource",
"->",
"isPaused",
"(",
")",
"&&",
"$",
"resource",
"->",
"isReadable",
"(",
")",
")",
"{",
"$",
"resource",
"->",
"handleRead",
"(",
")",
";",
"}",
"}",
"// handle all writing",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"!",
"$",
"resource",
"->",
"isPaused",
"(",
")",
"&&",
"$",
"resource",
"->",
"isWritable",
"(",
")",
")",
"{",
"$",
"resource",
"->",
"handleWrite",
"(",
")",
";",
"}",
"}",
"}"
]
| Handle data.
@internal | [
"Handle",
"data",
"."
]
| 8e48867f7b147a7b27bd4e995ac42e6df65c17bb | https://github.com/dazzle-php/ssh/blob/8e48867f7b147a7b27bd4e995ac42e6df65c17bb/src/SSH/Driver/Sftp.php#L279-L303 | train |
dazzle-php/ssh | src/SSH/Driver/Sftp.php | Sftp.removeResource | private function removeResource($prefix)
{
if (!isset($this->resources[$prefix]))
{
return;
}
unset($this->resources[$prefix]);
$this->resourcesCounter--;
if ($this->resourcesCounter === 0)
{
$this->pause();
}
} | php | private function removeResource($prefix)
{
if (!isset($this->resources[$prefix]))
{
return;
}
unset($this->resources[$prefix]);
$this->resourcesCounter--;
if ($this->resourcesCounter === 0)
{
$this->pause();
}
} | [
"private",
"function",
"removeResource",
"(",
"$",
"prefix",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"resources",
"[",
"$",
"prefix",
"]",
")",
")",
"{",
"return",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"resources",
"[",
"$",
"prefix",
"]",
")",
";",
"$",
"this",
"->",
"resourcesCounter",
"--",
";",
"if",
"(",
"$",
"this",
"->",
"resourcesCounter",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"pause",
"(",
")",
";",
"}",
"}"
]
| Remove resource from known collection.
@param string $prefix | [
"Remove",
"resource",
"from",
"known",
"collection",
"."
]
| 8e48867f7b147a7b27bd4e995ac42e6df65c17bb | https://github.com/dazzle-php/ssh/blob/8e48867f7b147a7b27bd4e995ac42e6df65c17bb/src/SSH/Driver/Sftp.php#L328-L342 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/AbstractSelectableInput.php | AbstractSelectableInput.parseChoiceVal | protected function parseChoiceVal($value)
{
if ($value instanceof ModelInterface) {
$value = $value->id();
}
if ($value instanceof Closure) {
$value = $value();
}
if ($value instanceof DateTimeInterface) {
$value = $value->format('Y-m-d-H:i');
}
if (method_exists($value, '__toString')) {
$value = strval($value);
}
return $value;
} | php | protected function parseChoiceVal($value)
{
if ($value instanceof ModelInterface) {
$value = $value->id();
}
if ($value instanceof Closure) {
$value = $value();
}
if ($value instanceof DateTimeInterface) {
$value = $value->format('Y-m-d-H:i');
}
if (method_exists($value, '__toString')) {
$value = strval($value);
}
return $value;
} | [
"protected",
"function",
"parseChoiceVal",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"ModelInterface",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"id",
"(",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"Closure",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"(",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"DateTimeInterface",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"format",
"(",
"'Y-m-d-H:i'",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"$",
"value",
"=",
"strval",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
]
| Convert the value to a scalar.
@param mixed $value A value to parse.
@return mixed | [
"Convert",
"the",
"value",
"to",
"a",
"scalar",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractSelectableInput.php#L99-L118 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/AbstractSelectableInput.php | AbstractSelectableInput.parsedVal | public function parsedVal()
{
if (!isset($this->parsedVal[$this->lang()])) {
$val = $this->propertyVal();
if ($val === null) {
return null;
}
$val = $this->p()->parseVal($val);
// Could be Translation instance
// Could be array
if (isset($val[$this->lang()])) {
$val = $val[$this->lang()];
}
// Doing this in the parseVal method of abstract property
// was causing multiple && l10n properties not to save.
if (!is_array($val) && $this->p()->multiple()) {
$val = explode($this->p()->multipleSeparator(), $val);
}
$this->parsedVal[$this->lang()] = $val;
}
return $this->parsedVal[$this->lang()];
} | php | public function parsedVal()
{
if (!isset($this->parsedVal[$this->lang()])) {
$val = $this->propertyVal();
if ($val === null) {
return null;
}
$val = $this->p()->parseVal($val);
// Could be Translation instance
// Could be array
if (isset($val[$this->lang()])) {
$val = $val[$this->lang()];
}
// Doing this in the parseVal method of abstract property
// was causing multiple && l10n properties not to save.
if (!is_array($val) && $this->p()->multiple()) {
$val = explode($this->p()->multipleSeparator(), $val);
}
$this->parsedVal[$this->lang()] = $val;
}
return $this->parsedVal[$this->lang()];
} | [
"public",
"function",
"parsedVal",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parsedVal",
"[",
"$",
"this",
"->",
"lang",
"(",
")",
"]",
")",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"propertyVal",
"(",
")",
";",
"if",
"(",
"$",
"val",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"val",
"=",
"$",
"this",
"->",
"p",
"(",
")",
"->",
"parseVal",
"(",
"$",
"val",
")",
";",
"// Could be Translation instance",
"// Could be array",
"if",
"(",
"isset",
"(",
"$",
"val",
"[",
"$",
"this",
"->",
"lang",
"(",
")",
"]",
")",
")",
"{",
"$",
"val",
"=",
"$",
"val",
"[",
"$",
"this",
"->",
"lang",
"(",
")",
"]",
";",
"}",
"// Doing this in the parseVal method of abstract property",
"// was causing multiple && l10n properties not to save.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"val",
")",
"&&",
"$",
"this",
"->",
"p",
"(",
")",
"->",
"multiple",
"(",
")",
")",
"{",
"$",
"val",
"=",
"explode",
"(",
"$",
"this",
"->",
"p",
"(",
")",
"->",
"multipleSeparator",
"(",
")",
",",
"$",
"val",
")",
";",
"}",
"$",
"this",
"->",
"parsedVal",
"[",
"$",
"this",
"->",
"lang",
"(",
")",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"this",
"->",
"parsedVal",
"[",
"$",
"this",
"->",
"lang",
"(",
")",
"]",
";",
"}"
]
| Keep parsed val in memory per lang
@return mixed Parsed property value. | [
"Keep",
"parsed",
"val",
"in",
"memory",
"per",
"lang"
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractSelectableInput.php#L125-L150 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/AbstractSelectableInput.php | AbstractSelectableInput.isChoiceSelected | public function isChoiceSelected($choice)
{
$val = $this->parsedVal();
if ($val === null) {
return false;
}
if (isset($choice['value'])) {
$choice = $choice['value'];
}
if ($this->p()->multiple()) {
return in_array($choice, $val);
} else {
return $choice == $val;
}
} | php | public function isChoiceSelected($choice)
{
$val = $this->parsedVal();
if ($val === null) {
return false;
}
if (isset($choice['value'])) {
$choice = $choice['value'];
}
if ($this->p()->multiple()) {
return in_array($choice, $val);
} else {
return $choice == $val;
}
} | [
"public",
"function",
"isChoiceSelected",
"(",
"$",
"choice",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"parsedVal",
"(",
")",
";",
"if",
"(",
"$",
"val",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"choice",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"choice",
"=",
"$",
"choice",
"[",
"'value'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"p",
"(",
")",
"->",
"multiple",
"(",
")",
")",
"{",
"return",
"in_array",
"(",
"$",
"choice",
",",
"$",
"val",
")",
";",
"}",
"else",
"{",
"return",
"$",
"choice",
"==",
"$",
"val",
";",
"}",
"}"
]
| Determine if the provided option is a selected value.
@param mixed $choice The choice to check.
@return boolean | [
"Determine",
"if",
"the",
"provided",
"option",
"is",
"a",
"selected",
"value",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractSelectableInput.php#L158-L175 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/AbstractSelectableInput.php | AbstractSelectableInput.setEmptyChoice | public function setEmptyChoice($choice)
{
if (is_string($choice) || ($choice instanceof Translation)) {
$choice = [
'label' => $choice
];
}
if (is_array($choice)) {
$choice = array_replace_recursive(
$this->defaultEmptyChoice(),
$choice
);
} else {
throw new InvalidArgumentException(sprintf(
'Empty choice must be an array, received %s',
(is_object($choice) ? get_class($choice) : gettype($choice))
));
}
if (!$choice['label'] instanceof Translation) {
$choice['label'] = $this->translator()->translation($choice['label']);
}
$this->emptyChoice = $choice;
return $this;
} | php | public function setEmptyChoice($choice)
{
if (is_string($choice) || ($choice instanceof Translation)) {
$choice = [
'label' => $choice
];
}
if (is_array($choice)) {
$choice = array_replace_recursive(
$this->defaultEmptyChoice(),
$choice
);
} else {
throw new InvalidArgumentException(sprintf(
'Empty choice must be an array, received %s',
(is_object($choice) ? get_class($choice) : gettype($choice))
));
}
if (!$choice['label'] instanceof Translation) {
$choice['label'] = $this->translator()->translation($choice['label']);
}
$this->emptyChoice = $choice;
return $this;
} | [
"public",
"function",
"setEmptyChoice",
"(",
"$",
"choice",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"choice",
")",
"||",
"(",
"$",
"choice",
"instanceof",
"Translation",
")",
")",
"{",
"$",
"choice",
"=",
"[",
"'label'",
"=>",
"$",
"choice",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"choice",
")",
")",
"{",
"$",
"choice",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"defaultEmptyChoice",
"(",
")",
",",
"$",
"choice",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Empty choice must be an array, received %s'",
",",
"(",
"is_object",
"(",
"$",
"choice",
")",
"?",
"get_class",
"(",
"$",
"choice",
")",
":",
"gettype",
"(",
"$",
"choice",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"choice",
"[",
"'label'",
"]",
"instanceof",
"Translation",
")",
"{",
"$",
"choice",
"[",
"'label'",
"]",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"translation",
"(",
"$",
"choice",
"[",
"'label'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"emptyChoice",
"=",
"$",
"choice",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the empty option's structure.
@param array|string $choice The property value.
@throws InvalidArgumentException If the choice structure is invalid.
@return PropertyInputInterface Chainable | [
"Set",
"the",
"empty",
"option",
"s",
"structure",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractSelectableInput.php#L184-L211 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/AbstractSelectableInput.php | AbstractSelectableInput.mapObjToChoice | public function mapObjToChoice($obj)
{
$map = $this->choiceObjMap();
$choice = [];
foreach ($map as $key => $props) {
$choice[$key] = null;
$props = explode(':', $props);
foreach ($props as $prop) {
$choice[$key] = $this->renderChoiceObjMap($obj, $prop);
break;
}
}
return $choice;
} | php | public function mapObjToChoice($obj)
{
$map = $this->choiceObjMap();
$choice = [];
foreach ($map as $key => $props) {
$choice[$key] = null;
$props = explode(':', $props);
foreach ($props as $prop) {
$choice[$key] = $this->renderChoiceObjMap($obj, $prop);
break;
}
}
return $choice;
} | [
"public",
"function",
"mapObjToChoice",
"(",
"$",
"obj",
")",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"choiceObjMap",
"(",
")",
";",
"$",
"choice",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"key",
"=>",
"$",
"props",
")",
"{",
"$",
"choice",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"$",
"props",
"=",
"explode",
"(",
"':'",
",",
"$",
"props",
")",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"prop",
")",
"{",
"$",
"choice",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"renderChoiceObjMap",
"(",
"$",
"obj",
",",
"$",
"prop",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"choice",
";",
"}"
]
| Convert the given object into a choice structure.
@param array|\ArrayAccess|ModelInterface $obj The object to map to a choice.
@return array | [
"Convert",
"the",
"given",
"object",
"into",
"a",
"choice",
"structure",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractSelectableInput.php#L289-L306 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Template/System/ClearCacheTemplate.php | ClearCacheTemplate.secondaryMenu | public function secondaryMenu()
{
if ($this->secondaryMenu === null) {
$this->secondaryMenu = $this->createSecondaryMenu('system');
}
return $this->secondaryMenu;
} | php | public function secondaryMenu()
{
if ($this->secondaryMenu === null) {
$this->secondaryMenu = $this->createSecondaryMenu('system');
}
return $this->secondaryMenu;
} | [
"public",
"function",
"secondaryMenu",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"secondaryMenu",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"secondaryMenu",
"=",
"$",
"this",
"->",
"createSecondaryMenu",
"(",
"'system'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"secondaryMenu",
";",
"}"
]
| Retrieve the secondary menu.
@return \Charcoal\Admin\Widget\SecondaryMenuWidgetInterface|null | [
"Retrieve",
"the",
"secondary",
"menu",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/System/ClearCacheTemplate.php#L80-L87 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Template/System/ClearCacheTemplate.php | ClearCacheTemplate.formatTimeDiff | private function formatTimeDiff(DateTimeInterface $date1, DateTimeInterface $date2 = null)
{
$isNow = $date2 === null;
if ($isNow) {
$date2 = new DateTime('now', $date1->getTimezone());
}
$interval = $date1->diff($date2);
$translator = $this->translator();
switch (true) {
case ($interval->y > 0):
$unit = 'time.year';
$count = $interval->y;
break;
case ($interval->m > 0):
$unit = 'time.month';
$count = $interval->m;
break;
case ($interval->d > 0):
$unit = 'time.day';
$count = $interval->d;
if ($count >= 7) {
$unit = 'time.week';
$count = (int)($count / 7);
}
break;
case ($interval->h > 0):
$unit = 'time.hour';
$count = $interval->h;
break;
case ($interval->i > 0):
$unit = 'time.minute';
$count = $interval->i;
break;
default:
$count = $interval->s;
$unit = 'time.second';
break;
}
$time = $translator->transChoice($unit, $count, [ '{{ count }}' => $count ]);
return $time;
} | php | private function formatTimeDiff(DateTimeInterface $date1, DateTimeInterface $date2 = null)
{
$isNow = $date2 === null;
if ($isNow) {
$date2 = new DateTime('now', $date1->getTimezone());
}
$interval = $date1->diff($date2);
$translator = $this->translator();
switch (true) {
case ($interval->y > 0):
$unit = 'time.year';
$count = $interval->y;
break;
case ($interval->m > 0):
$unit = 'time.month';
$count = $interval->m;
break;
case ($interval->d > 0):
$unit = 'time.day';
$count = $interval->d;
if ($count >= 7) {
$unit = 'time.week';
$count = (int)($count / 7);
}
break;
case ($interval->h > 0):
$unit = 'time.hour';
$count = $interval->h;
break;
case ($interval->i > 0):
$unit = 'time.minute';
$count = $interval->i;
break;
default:
$count = $interval->s;
$unit = 'time.second';
break;
}
$time = $translator->transChoice($unit, $count, [ '{{ count }}' => $count ]);
return $time;
} | [
"private",
"function",
"formatTimeDiff",
"(",
"DateTimeInterface",
"$",
"date1",
",",
"DateTimeInterface",
"$",
"date2",
"=",
"null",
")",
"{",
"$",
"isNow",
"=",
"$",
"date2",
"===",
"null",
";",
"if",
"(",
"$",
"isNow",
")",
"{",
"$",
"date2",
"=",
"new",
"DateTime",
"(",
"'now'",
",",
"$",
"date1",
"->",
"getTimezone",
"(",
")",
")",
";",
"}",
"$",
"interval",
"=",
"$",
"date1",
"->",
"diff",
"(",
"$",
"date2",
")",
";",
"$",
"translator",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"$",
"interval",
"->",
"y",
">",
"0",
")",
":",
"$",
"unit",
"=",
"'time.year'",
";",
"$",
"count",
"=",
"$",
"interval",
"->",
"y",
";",
"break",
";",
"case",
"(",
"$",
"interval",
"->",
"m",
">",
"0",
")",
":",
"$",
"unit",
"=",
"'time.month'",
";",
"$",
"count",
"=",
"$",
"interval",
"->",
"m",
";",
"break",
";",
"case",
"(",
"$",
"interval",
"->",
"d",
">",
"0",
")",
":",
"$",
"unit",
"=",
"'time.day'",
";",
"$",
"count",
"=",
"$",
"interval",
"->",
"d",
";",
"if",
"(",
"$",
"count",
">=",
"7",
")",
"{",
"$",
"unit",
"=",
"'time.week'",
";",
"$",
"count",
"=",
"(",
"int",
")",
"(",
"$",
"count",
"/",
"7",
")",
";",
"}",
"break",
";",
"case",
"(",
"$",
"interval",
"->",
"h",
">",
"0",
")",
":",
"$",
"unit",
"=",
"'time.hour'",
";",
"$",
"count",
"=",
"$",
"interval",
"->",
"h",
";",
"break",
";",
"case",
"(",
"$",
"interval",
"->",
"i",
">",
"0",
")",
":",
"$",
"unit",
"=",
"'time.minute'",
";",
"$",
"count",
"=",
"$",
"interval",
"->",
"i",
";",
"break",
";",
"default",
":",
"$",
"count",
"=",
"$",
"interval",
"->",
"s",
";",
"$",
"unit",
"=",
"'time.second'",
";",
"break",
";",
"}",
"$",
"time",
"=",
"$",
"translator",
"->",
"transChoice",
"(",
"$",
"unit",
",",
"$",
"count",
",",
"[",
"'{{ count }}'",
"=>",
"$",
"count",
"]",
")",
";",
"return",
"$",
"time",
";",
"}"
]
| Human-readable time difference.
Note: Adapted from CakePHP\Chronos.
@see https://github.com/cakephp/chronos/blob/1.1.4/LICENSE
@param DateTimeInterface $date1 The datetime to start with.
@param DateTimeInterface|null $date2 The datetime to compare against.
@return string | [
"Human",
"-",
"readable",
"time",
"difference",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/System/ClearCacheTemplate.php#L442-L486 | train |
acquia/commerce-manager | modules/acm_sku/src/AcquiaCommerce/SKUPluginManager.php | SKUPluginManager.pluginFromSku | public function pluginFromSku(SKU $sku) {
if (empty($sku)) {
return NULL;
}
$bundle = $sku->getType();
if (empty($bundle)) {
return NULL;
}
$plugin = NULL;
try {
$plugin = $this->getDefinition($bundle);
}
catch (PluginNotFoundException $exception) {
\Drupal::logger('acm_sku')->notice(t("Bundle @bundle doesn't appear to
have an implementation, please check the plugin id on your implementation
of the SKU plugin", ['@bundle' => $bundle]));
} finally {
return $plugin;
}
} | php | public function pluginFromSku(SKU $sku) {
if (empty($sku)) {
return NULL;
}
$bundle = $sku->getType();
if (empty($bundle)) {
return NULL;
}
$plugin = NULL;
try {
$plugin = $this->getDefinition($bundle);
}
catch (PluginNotFoundException $exception) {
\Drupal::logger('acm_sku')->notice(t("Bundle @bundle doesn't appear to
have an implementation, please check the plugin id on your implementation
of the SKU plugin", ['@bundle' => $bundle]));
} finally {
return $plugin;
}
} | [
"public",
"function",
"pluginFromSku",
"(",
"SKU",
"$",
"sku",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sku",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"$",
"bundle",
"=",
"$",
"sku",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"bundle",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"$",
"plugin",
"=",
"NULL",
";",
"try",
"{",
"$",
"plugin",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
"$",
"bundle",
")",
";",
"}",
"catch",
"(",
"PluginNotFoundException",
"$",
"exception",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"notice",
"(",
"t",
"(",
"\"Bundle @bundle doesn't appear to\n have an implementation, please check the plugin id on your implementation\n of the SKU plugin\"",
",",
"[",
"'@bundle'",
"=>",
"$",
"bundle",
"]",
")",
")",
";",
"}",
"finally",
"{",
"return",
"$",
"plugin",
";",
"}",
"}"
]
| Takes a SKU entity and checks it for a matching plugin.
@param \Drupal\acm_sku\Entity\SKU $sku
The SKU to check for a plugin.
@return array|null
Returns the plugin definition if found, otherwise returns NULL. | [
"Takes",
"a",
"SKU",
"entity",
"and",
"checks",
"it",
"for",
"a",
"matching",
"plugin",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/AcquiaCommerce/SKUPluginManager.php#L54-L77 | train |
acquia/commerce-manager | modules/acm_sku/src/AcquiaCommerce/SKUPluginManager.php | SKUPluginManager.pluginInstanceFromType | public function pluginInstanceFromType($type) {
$plugin = NULL;
try {
$plugin = $this->getDefinition($type);
$plugin = $this->createInstance($plugin['id']);
}
catch (\Exception $exception) {
\Drupal::logger('acm_sku')->notice(t("Bundle @bundle doesn't appear to
have an implementation, please check the plugin id on your implementation
of the SKU plugin", ['@bundle' => $type]));
} finally {
return $plugin;
}
} | php | public function pluginInstanceFromType($type) {
$plugin = NULL;
try {
$plugin = $this->getDefinition($type);
$plugin = $this->createInstance($plugin['id']);
}
catch (\Exception $exception) {
\Drupal::logger('acm_sku')->notice(t("Bundle @bundle doesn't appear to
have an implementation, please check the plugin id on your implementation
of the SKU plugin", ['@bundle' => $type]));
} finally {
return $plugin;
}
} | [
"public",
"function",
"pluginInstanceFromType",
"(",
"$",
"type",
")",
"{",
"$",
"plugin",
"=",
"NULL",
";",
"try",
"{",
"$",
"plugin",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
"$",
"type",
")",
";",
"$",
"plugin",
"=",
"$",
"this",
"->",
"createInstance",
"(",
"$",
"plugin",
"[",
"'id'",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"notice",
"(",
"t",
"(",
"\"Bundle @bundle doesn't appear to\n have an implementation, please check the plugin id on your implementation\n of the SKU plugin\"",
",",
"[",
"'@bundle'",
"=>",
"$",
"type",
"]",
")",
")",
";",
"}",
"finally",
"{",
"return",
"$",
"plugin",
";",
"}",
"}"
]
| Takes a type and checks it for a matching plugin.
@param string $type
The SKU to check for a plugin.
@return array|null
Returns the plugin definition if found, otherwise returns NULL. | [
"Takes",
"a",
"type",
"and",
"checks",
"it",
"for",
"a",
"matching",
"plugin",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/AcquiaCommerce/SKUPluginManager.php#L88-L102 | train |
acquia/commerce-manager | modules/acm_customer/src/Controller/CustomerController.php | CustomerController.formPage | public function formPage($action = NULL, $id = NULL) {
$plugin = $this->customerPagesManager->createInstance($this->customerPagesPlugin, ['action' => $action, 'id' => $id]);
$form_state = new FormState();
$form = $this->formBuilder->buildForm($plugin, $form_state);
$form['#attached']['library'][] = 'core/jquery.form';
$form['#attached']['library'][] = 'core/drupal.ajax';
$form['#attached']['library'][] = 'acm_customer/single_page_app';
$form['#attached']['drupalSettings']['acm_customer'] = [
'customerPagesPath' => Url::fromRoute('acm_customer.view_page')->toString(),
'ajaxCustomerPagesPath' => Url::fromRoute('acm_customer.ajax_view_page')->toString(),
];
return $form;
} | php | public function formPage($action = NULL, $id = NULL) {
$plugin = $this->customerPagesManager->createInstance($this->customerPagesPlugin, ['action' => $action, 'id' => $id]);
$form_state = new FormState();
$form = $this->formBuilder->buildForm($plugin, $form_state);
$form['#attached']['library'][] = 'core/jquery.form';
$form['#attached']['library'][] = 'core/drupal.ajax';
$form['#attached']['library'][] = 'acm_customer/single_page_app';
$form['#attached']['drupalSettings']['acm_customer'] = [
'customerPagesPath' => Url::fromRoute('acm_customer.view_page')->toString(),
'ajaxCustomerPagesPath' => Url::fromRoute('acm_customer.ajax_view_page')->toString(),
];
return $form;
} | [
"public",
"function",
"formPage",
"(",
"$",
"action",
"=",
"NULL",
",",
"$",
"id",
"=",
"NULL",
")",
"{",
"$",
"plugin",
"=",
"$",
"this",
"->",
"customerPagesManager",
"->",
"createInstance",
"(",
"$",
"this",
"->",
"customerPagesPlugin",
",",
"[",
"'action'",
"=>",
"$",
"action",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"$",
"form_state",
"=",
"new",
"FormState",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"formBuilder",
"->",
"buildForm",
"(",
"$",
"plugin",
",",
"$",
"form_state",
")",
";",
"$",
"form",
"[",
"'#attached'",
"]",
"[",
"'library'",
"]",
"[",
"]",
"=",
"'core/jquery.form'",
";",
"$",
"form",
"[",
"'#attached'",
"]",
"[",
"'library'",
"]",
"[",
"]",
"=",
"'core/drupal.ajax'",
";",
"$",
"form",
"[",
"'#attached'",
"]",
"[",
"'library'",
"]",
"[",
"]",
"=",
"'acm_customer/single_page_app'",
";",
"$",
"form",
"[",
"'#attached'",
"]",
"[",
"'drupalSettings'",
"]",
"[",
"'acm_customer'",
"]",
"=",
"[",
"'customerPagesPath'",
"=>",
"Url",
"::",
"fromRoute",
"(",
"'acm_customer.view_page'",
")",
"->",
"toString",
"(",
")",
",",
"'ajaxCustomerPagesPath'",
"=>",
"Url",
"::",
"fromRoute",
"(",
"'acm_customer.ajax_view_page'",
")",
"->",
"toString",
"(",
")",
",",
"]",
";",
"return",
"$",
"form",
";",
"}"
]
| Renders a customer page.
@param string $action
The action route parameter.
@param string $id
The id route parameter. | [
"Renders",
"a",
"customer",
"page",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Controller/CustomerController.php#L133-L145 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.