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/Widget/ObjectFormWidget.php | ObjectFormWidget.groupsConditionalLogic | protected function groupsConditionalLogic(array $groups = null)
{
if (!$groups) {
$groups = iterator_to_array($this->groups());
}
$conditions = [];
foreach ($groups as $group) {
if ($group instanceof FormInterface) {
$groupGroups = iterator_to_array($group->groups());
if (!empty($groupGroups)) {
$conditions = array_merge(
$conditions,
$this->groupsConditionalLogic($groupGroups)
);
}
}
if ($group instanceof FormGroupInterface && $group->conditionalLogic()) {
$conditions = array_merge($conditions, $group->conditionalLogic());
}
}
return $conditions;
} | php | protected function groupsConditionalLogic(array $groups = null)
{
if (!$groups) {
$groups = iterator_to_array($this->groups());
}
$conditions = [];
foreach ($groups as $group) {
if ($group instanceof FormInterface) {
$groupGroups = iterator_to_array($group->groups());
if (!empty($groupGroups)) {
$conditions = array_merge(
$conditions,
$this->groupsConditionalLogic($groupGroups)
);
}
}
if ($group instanceof FormGroupInterface && $group->conditionalLogic()) {
$conditions = array_merge($conditions, $group->conditionalLogic());
}
}
return $conditions;
} | [
"protected",
"function",
"groupsConditionalLogic",
"(",
"array",
"$",
"groups",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"groups",
")",
"{",
"$",
"groups",
"=",
"iterator_to_array",
"(",
"$",
"this",
"->",
"groups",
"(",
")",
")",
";",
"}",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"$",
"group",
"instanceof",
"FormInterface",
")",
"{",
"$",
"groupGroups",
"=",
"iterator_to_array",
"(",
"$",
"group",
"->",
"groups",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"groupGroups",
")",
")",
"{",
"$",
"conditions",
"=",
"array_merge",
"(",
"$",
"conditions",
",",
"$",
"this",
"->",
"groupsConditionalLogic",
"(",
"$",
"groupGroups",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"group",
"instanceof",
"FormGroupInterface",
"&&",
"$",
"group",
"->",
"conditionalLogic",
"(",
")",
")",
"{",
"$",
"conditions",
"=",
"array_merge",
"(",
"$",
"conditions",
",",
"$",
"group",
"->",
"conditionalLogic",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"conditions",
";",
"}"
]
| Self recursive when a groups is an instance of FormInterface.
@param array|null $groups Form groups to parse.
@return array | [
"Self",
"recursive",
"when",
"a",
"groups",
"is",
"an",
"instance",
"of",
"FormInterface",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/ObjectFormWidget.php#L348-L373 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.widgetId | public function widgetId()
{
if (!$this->widgetId) {
$type = $this->type();
switch ($type) {
case static::PROPERTY_DISPLAY:
$id = $this->display()->displayId();
break;
case static::PROPERTY_CONTROL:
$id = $this->input()->inputId();
break;
default:
$id = 'widget_'.uniqid();
break;
}
$this->widgetId = $id;
}
return $this->widgetId;
} | php | public function widgetId()
{
if (!$this->widgetId) {
$type = $this->type();
switch ($type) {
case static::PROPERTY_DISPLAY:
$id = $this->display()->displayId();
break;
case static::PROPERTY_CONTROL:
$id = $this->input()->inputId();
break;
default:
$id = 'widget_'.uniqid();
break;
}
$this->widgetId = $id;
}
return $this->widgetId;
} | [
"public",
"function",
"widgetId",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"widgetId",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"type",
"(",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"static",
"::",
"PROPERTY_DISPLAY",
":",
"$",
"id",
"=",
"$",
"this",
"->",
"display",
"(",
")",
"->",
"displayId",
"(",
")",
";",
"break",
";",
"case",
"static",
"::",
"PROPERTY_CONTROL",
":",
"$",
"id",
"=",
"$",
"this",
"->",
"input",
"(",
")",
"->",
"inputId",
"(",
")",
";",
"break",
";",
"default",
":",
"$",
"id",
"=",
"'widget_'",
".",
"uniqid",
"(",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"widgetId",
"=",
"$",
"id",
";",
"}",
"return",
"$",
"this",
"->",
"widgetId",
";",
"}"
]
| Retrieve the widget ID.
@return string | [
"Retrieve",
"the",
"widget",
"ID",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L267-L289 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setType | public function setType($type)
{
if (empty($type)) {
$this->type = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Form property widget type must be a string'
);
}
if ($this->propertyFactory()->isResolvable($type)) {
$this->setPropertyType($type);
}
$this->type = $type;
return $this;
} | php | public function setType($type)
{
if (empty($type)) {
$this->type = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Form property widget type must be a string'
);
}
if ($this->propertyFactory()->isResolvable($type)) {
$this->setPropertyType($type);
}
$this->type = $type;
return $this;
} | [
"public",
"function",
"setType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Form property widget type must be a string'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"propertyFactory",
"(",
")",
"->",
"isResolvable",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"setPropertyType",
"(",
"$",
"type",
")",
";",
"}",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the widget or property type.
@param string $type The widget or property type.
@throws InvalidArgumentException If the argument is not a string.
@return FormPropertyWidget Chainable | [
"Set",
"the",
"widget",
"or",
"property",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L298-L318 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.outputType | public function outputType()
{
if ($this->outputType === null) {
if ($this->inputType === false && $this->displayType === false) {
throw new LogicException('Form property widget requires an "input_type" or a "display_type"');
}
$type = null;
if ($this->inputType === false || is_string($this->displayType)) {
$type = static::PROPERTY_DISPLAY;
}
if ($this->displayType === false || is_string($this->inputType)) {
$type = static::PROPERTY_CONTROL;
}
$this->outputType = $type;
}
return $this->outputType;
} | php | public function outputType()
{
if ($this->outputType === null) {
if ($this->inputType === false && $this->displayType === false) {
throw new LogicException('Form property widget requires an "input_type" or a "display_type"');
}
$type = null;
if ($this->inputType === false || is_string($this->displayType)) {
$type = static::PROPERTY_DISPLAY;
}
if ($this->displayType === false || is_string($this->inputType)) {
$type = static::PROPERTY_CONTROL;
}
$this->outputType = $type;
}
return $this->outputType;
} | [
"public",
"function",
"outputType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"outputType",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"inputType",
"===",
"false",
"&&",
"$",
"this",
"->",
"displayType",
"===",
"false",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Form property widget requires an \"input_type\" or a \"display_type\"'",
")",
";",
"}",
"$",
"type",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"inputType",
"===",
"false",
"||",
"is_string",
"(",
"$",
"this",
"->",
"displayType",
")",
")",
"{",
"$",
"type",
"=",
"static",
"::",
"PROPERTY_DISPLAY",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"displayType",
"===",
"false",
"||",
"is_string",
"(",
"$",
"this",
"->",
"inputType",
")",
")",
"{",
"$",
"type",
"=",
"static",
"::",
"PROPERTY_CONTROL",
";",
"}",
"$",
"this",
"->",
"outputType",
"=",
"$",
"type",
";",
"}",
"return",
"$",
"this",
"->",
"outputType",
";",
"}"
]
| Retrieve the widget's property output type.
Defaults to "input_type".
@throws LogicException If the "input_type" and "display_type" are disabled.
@return string|null | [
"Retrieve",
"the",
"widget",
"s",
"property",
"output",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L360-L381 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setData | public function setData(array $data)
{
$this->isMergingWidgetData = true;
$data = $this->setCoreData($data);
parent::setData($data);
// Keep the data in copy, this will be passed to the property and/or input later
$this->setPropertyData($data);
$this->isMergingWidgetData = false;
return $this;
} | php | public function setData(array $data)
{
$this->isMergingWidgetData = true;
$data = $this->setCoreData($data);
parent::setData($data);
// Keep the data in copy, this will be passed to the property and/or input later
$this->setPropertyData($data);
$this->isMergingWidgetData = false;
return $this;
} | [
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"isMergingWidgetData",
"=",
"true",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"setCoreData",
"(",
"$",
"data",
")",
";",
"parent",
"::",
"setData",
"(",
"$",
"data",
")",
";",
"// Keep the data in copy, this will be passed to the property and/or input later",
"$",
"this",
"->",
"setPropertyData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"isMergingWidgetData",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the widget and property data.
@param array|ArrayAccess $data Widget and property data.
@return FormPropertyWidget Chainable | [
"Set",
"the",
"widget",
"and",
"property",
"data",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L436-L450 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.merge | public function merge(array $data)
{
$this->isMergingWidgetData = true;
$data = $this->setCoreData($data);
$this->mergePropertyData($data);
$this->isMergingWidgetData = false;
return $this;
} | php | public function merge(array $data)
{
$this->isMergingWidgetData = true;
$data = $this->setCoreData($data);
$this->mergePropertyData($data);
$this->isMergingWidgetData = false;
return $this;
} | [
"public",
"function",
"merge",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"isMergingWidgetData",
"=",
"true",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"setCoreData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"mergePropertyData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"isMergingWidgetData",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
]
| Merge widget and property data.
@param array $data Widget and property data.
@return FormPropertyWidget Chainable | [
"Merge",
"widget",
"and",
"property",
"data",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L458-L469 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setPropertyData | public function setPropertyData(array $data)
{
$this->propertyData = $data;
if (!$this->isMergingWidgetData) {
$this->setCoreData($this->propertyData);
}
if ($this->property) {
$this->property->setData($data);
}
return $this;
} | php | public function setPropertyData(array $data)
{
$this->propertyData = $data;
if (!$this->isMergingWidgetData) {
$this->setCoreData($this->propertyData);
}
if ($this->property) {
$this->property->setData($data);
}
return $this;
} | [
"public",
"function",
"setPropertyData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"propertyData",
"=",
"$",
"data",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isMergingWidgetData",
")",
"{",
"$",
"this",
"->",
"setCoreData",
"(",
"$",
"this",
"->",
"propertyData",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"this",
"->",
"property",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the property metadata.
@param array $data The property configset.
@return FormPropertyWidget Chainable | [
"Set",
"the",
"property",
"metadata",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L542-L555 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.mergePropertyData | public function mergePropertyData(array $data)
{
$this->propertyData = array_replace($this->propertyData, $data);
if (!$this->isMergingWidgetData) {
$this->setCoreData($this->propertyData);
}
if ($this->property) {
$this->property->setData($data);
}
return $this;
} | php | public function mergePropertyData(array $data)
{
$this->propertyData = array_replace($this->propertyData, $data);
if (!$this->isMergingWidgetData) {
$this->setCoreData($this->propertyData);
}
if ($this->property) {
$this->property->setData($data);
}
return $this;
} | [
"public",
"function",
"mergePropertyData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"propertyData",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"propertyData",
",",
"$",
"data",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isMergingWidgetData",
")",
"{",
"$",
"this",
"->",
"setCoreData",
"(",
"$",
"this",
"->",
"propertyData",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"this",
"->",
"property",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Merge the property metadata.
@param array $data The property configset.
@return FormPropertyWidget Chainable | [
"Merge",
"the",
"property",
"metadata",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L563-L576 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.showLabel | public function showLabel()
{
if ($this->showLabel === null) {
$prop = $this->property();
$show = $prop['show_label'];
if ($show !== null) {
$this->showLabel = $show;
} else {
$this->showLabel = true;
}
}
if ($this->showLabel !== false) {
return !!strval($this->property()->label());
} else {
return false;
}
} | php | public function showLabel()
{
if ($this->showLabel === null) {
$prop = $this->property();
$show = $prop['show_label'];
if ($show !== null) {
$this->showLabel = $show;
} else {
$this->showLabel = true;
}
}
if ($this->showLabel !== false) {
return !!strval($this->property()->label());
} else {
return false;
}
} | [
"public",
"function",
"showLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showLabel",
"===",
"null",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"show",
"=",
"$",
"prop",
"[",
"'show_label'",
"]",
";",
"if",
"(",
"$",
"show",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"showLabel",
"=",
"$",
"show",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"showLabel",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"showLabel",
"!==",
"false",
")",
"{",
"return",
"!",
"!",
"strval",
"(",
"$",
"this",
"->",
"property",
"(",
")",
"->",
"label",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Determine if the label is to be displayed.
@return boolean If TRUE or unset, check if there is a label. | [
"Determine",
"if",
"the",
"label",
"is",
"to",
"be",
"displayed",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L629-L646 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.showDescription | public function showDescription()
{
if ($this->showDescription === null) {
$prop = $this->property();
$show = $prop['show_description'];
if ($show !== null) {
$this->showDescription = $show;
} else {
$this->showDescription = true;
}
}
if ($this->showDescription !== false) {
return !!strval($this->property()->description());
} else {
return false;
}
} | php | public function showDescription()
{
if ($this->showDescription === null) {
$prop = $this->property();
$show = $prop['show_description'];
if ($show !== null) {
$this->showDescription = $show;
} else {
$this->showDescription = true;
}
}
if ($this->showDescription !== false) {
return !!strval($this->property()->description());
} else {
return false;
}
} | [
"public",
"function",
"showDescription",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showDescription",
"===",
"null",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"show",
"=",
"$",
"prop",
"[",
"'show_description'",
"]",
";",
"if",
"(",
"$",
"show",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"showDescription",
"=",
"$",
"show",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"showDescription",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"showDescription",
"!==",
"false",
")",
"{",
"return",
"!",
"!",
"strval",
"(",
"$",
"this",
"->",
"property",
"(",
")",
"->",
"description",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Determine if the description is to be displayed.
@return boolean If TRUE or unset, check if there is a description. | [
"Determine",
"if",
"the",
"description",
"is",
"to",
"be",
"displayed",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L666-L683 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.showNotes | public function showNotes()
{
if ($this->showNotes === null) {
$prop = $this->property();
$show = $prop['show_notes'];
if ($show !== null) {
$this->showNotes = $show;
} else {
$this->showNotes = true;
}
}
if ($this->showNotes !== false) {
return !!strval($this->property()->notes());
} else {
return false;
}
} | php | public function showNotes()
{
if ($this->showNotes === null) {
$prop = $this->property();
$show = $prop['show_notes'];
if ($show !== null) {
$this->showNotes = $show;
} else {
$this->showNotes = true;
}
}
if ($this->showNotes !== false) {
return !!strval($this->property()->notes());
} else {
return false;
}
} | [
"public",
"function",
"showNotes",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showNotes",
"===",
"null",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"show",
"=",
"$",
"prop",
"[",
"'show_notes'",
"]",
";",
"if",
"(",
"$",
"show",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"showNotes",
"=",
"$",
"show",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"showNotes",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"showNotes",
"!==",
"false",
")",
"{",
"return",
"!",
"!",
"strval",
"(",
"$",
"this",
"->",
"property",
"(",
")",
"->",
"notes",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Determine if the notes is to be displayed.
@return boolean If TRUE or unset, check if there are notes. | [
"Determine",
"if",
"the",
"notes",
"is",
"to",
"be",
"displayed",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L703-L720 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setInputType | public function setInputType($type)
{
if (empty($type)) {
$this->inputType = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Property input type must be a string'
);
}
$this->inputType = $type;
return $this;
} | php | public function setInputType($type)
{
if (empty($type)) {
$this->inputType = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Property input type must be a string'
);
}
$this->inputType = $type;
return $this;
} | [
"public",
"function",
"setInputType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"inputType",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Property input type must be a string'",
")",
";",
"}",
"$",
"this",
"->",
"inputType",
"=",
"$",
"type",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the property control type.
@param string $type The form control type.
@throws InvalidArgumentException If the argument is not a string.
@return FormPropertyWidget Chainable | [
"Set",
"the",
"property",
"control",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L805-L821 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.inputType | public function inputType()
{
if ($this->inputType === null) {
$this->inputType = $this->resolveInputType();
}
return $this->inputType;
} | php | public function inputType()
{
if ($this->inputType === null) {
$this->inputType = $this->resolveInputType();
}
return $this->inputType;
} | [
"public",
"function",
"inputType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"inputType",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"inputType",
"=",
"$",
"this",
"->",
"resolveInputType",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"inputType",
";",
"}"
]
| Retrieve the property control type.
@return string | [
"Retrieve",
"the",
"property",
"control",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L828-L835 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setDisplayType | public function setDisplayType($type)
{
if (empty($type)) {
$this->displayType = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Property display type must be a string'
);
}
$this->displayType = $type;
return $this;
} | php | public function setDisplayType($type)
{
if (empty($type)) {
$this->displayType = null;
return $this;
}
if (!is_string($type)) {
throw new InvalidArgumentException(
'Property display type must be a string'
);
}
$this->displayType = $type;
return $this;
} | [
"public",
"function",
"setDisplayType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"displayType",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Property display type must be a string'",
")",
";",
"}",
"$",
"this",
"->",
"displayType",
"=",
"$",
"type",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the property display type.
@param string $type The property display type.
@throws InvalidArgumentException If the argument is not a string.
@return FormPropertyWidget Chainable | [
"Set",
"the",
"property",
"display",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L844-L860 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.displayType | public function displayType()
{
if ($this->displayType === null) {
$this->displayType = $this->resolveDisplayType();
}
return $this->displayType;
} | php | public function displayType()
{
if ($this->displayType === null) {
$this->displayType = $this->resolveDisplayType();
}
return $this->displayType;
} | [
"public",
"function",
"displayType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"displayType",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"displayType",
"=",
"$",
"this",
"->",
"resolveDisplayType",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"displayType",
";",
"}"
]
| Retrieve the property display type.
@return string | [
"Retrieve",
"the",
"property",
"display",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L867-L874 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setProperty | public function setProperty(PropertyInterface $property)
{
$this->property = $property;
$this->propertyType = $property->type();
$this->propertyIdent = $property->ident();
$inputType = $property['input_type'];
if ($inputType) {
$this->inputType = $inputType;
}
$displayType = $property['display_type'];
if ($displayType) {
$this->displayType = $displayType;
}
return $this;
} | php | public function setProperty(PropertyInterface $property)
{
$this->property = $property;
$this->propertyType = $property->type();
$this->propertyIdent = $property->ident();
$inputType = $property['input_type'];
if ($inputType) {
$this->inputType = $inputType;
}
$displayType = $property['display_type'];
if ($displayType) {
$this->displayType = $displayType;
}
return $this;
} | [
"public",
"function",
"setProperty",
"(",
"PropertyInterface",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"property",
"=",
"$",
"property",
";",
"$",
"this",
"->",
"propertyType",
"=",
"$",
"property",
"->",
"type",
"(",
")",
";",
"$",
"this",
"->",
"propertyIdent",
"=",
"$",
"property",
"->",
"ident",
"(",
")",
";",
"$",
"inputType",
"=",
"$",
"property",
"[",
"'input_type'",
"]",
";",
"if",
"(",
"$",
"inputType",
")",
"{",
"$",
"this",
"->",
"inputType",
"=",
"$",
"inputType",
";",
"}",
"$",
"displayType",
"=",
"$",
"property",
"[",
"'display_type'",
"]",
";",
"if",
"(",
"$",
"displayType",
")",
"{",
"$",
"this",
"->",
"displayType",
"=",
"$",
"displayType",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the widget's model property.
@param PropertyInterface $property The property.
@return FormPropertyWidget Chainable | [
"Set",
"the",
"widget",
"s",
"model",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L882-L899 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.property | public function property()
{
if ($this->property === null) {
$this->property = $this->createProperty();
}
return $this->property;
} | php | public function property()
{
if ($this->property === null) {
$this->property = $this->createProperty();
}
return $this->property;
} | [
"public",
"function",
"property",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"property",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"property",
"=",
"$",
"this",
"->",
"createProperty",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"property",
";",
"}"
]
| Retrieve the widget's model property.
@return PropertyInterface | [
"Retrieve",
"the",
"widget",
"s",
"model",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L906-L913 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.showActiveLanguage | public function showActiveLanguage()
{
$property = $this->property();
$locales = count($this->translator()->availableLocales());
return ($locales > 1 && $property->l10n());
} | php | public function showActiveLanguage()
{
$property = $this->property();
$locales = count($this->translator()->availableLocales());
return ($locales > 1 && $property->l10n());
} | [
"public",
"function",
"showActiveLanguage",
"(",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"locales",
"=",
"count",
"(",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"availableLocales",
"(",
")",
")",
";",
"return",
"(",
"$",
"locales",
">",
"1",
"&&",
"$",
"property",
"->",
"l10n",
"(",
")",
")",
";",
"}"
]
| Determine if the form control's active language should be displayed.
@see FormSidebarWidget::showLanguageSwitch()
@return boolean | [
"Determine",
"if",
"the",
"form",
"control",
"s",
"active",
"language",
"should",
"be",
"displayed",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L931-L937 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.inputNameAsCssClass | public function inputNameAsCssClass()
{
$name = str_replace([ ']', '[' ], [ '', '-' ], $this->propertyIdent());
$name = $this->camelize($name);
return $name;
} | php | public function inputNameAsCssClass()
{
$name = str_replace([ ']', '[' ], [ '', '-' ], $this->propertyIdent());
$name = $this->camelize($name);
return $name;
} | [
"public",
"function",
"inputNameAsCssClass",
"(",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"[",
"']'",
",",
"'['",
"]",
",",
"[",
"''",
",",
"'-'",
"]",
",",
"$",
"this",
"->",
"propertyIdent",
"(",
")",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"camelize",
"(",
"$",
"name",
")",
";",
"return",
"$",
"name",
";",
"}"
]
| Generate a CSS class name for the property's input name.
@return string | [
"Generate",
"a",
"CSS",
"class",
"name",
"for",
"the",
"property",
"s",
"input",
"name",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L944-L950 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.input | public function input()
{
if ($this->inputProperty === null) {
$this->inputProperty = $this->createInputProperty();
}
return $this->inputProperty;
} | php | public function input()
{
if ($this->inputProperty === null) {
$this->inputProperty = $this->createInputProperty();
}
return $this->inputProperty;
} | [
"public",
"function",
"input",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"inputProperty",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"inputProperty",
"=",
"$",
"this",
"->",
"createInputProperty",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"inputProperty",
";",
"}"
]
| Retrieve the form control property.
@return PropertyInputInterface | [
"Retrieve",
"the",
"form",
"control",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1079-L1086 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.display | public function display()
{
if ($this->displayProperty === null) {
$this->displayProperty = $this->createDisplayProperty();
}
return $this->displayProperty;
} | php | public function display()
{
if ($this->displayProperty === null) {
$this->displayProperty = $this->createDisplayProperty();
}
return $this->displayProperty;
} | [
"public",
"function",
"display",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"displayProperty",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"displayProperty",
"=",
"$",
"this",
"->",
"createDisplayProperty",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"displayProperty",
";",
"}"
]
| Retrieve the display property.
@return PropertyDisplayInterface | [
"Retrieve",
"the",
"display",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1093-L1100 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.output | public function output()
{
$output = $this->outputType();
switch ($output) {
case static::PROPERTY_DISPLAY:
$type = $this->displayType();
$prop = $this->display();
$getter = 'displayId';
$setter = 'setDisplayId';
break;
case static::PROPERTY_CONTROL:
$type = $this->inputType();
$prop = $this->input();
$getter = 'inputId';
$setter = 'setInputId';
break;
}
$GLOBALS['widget_template'] = $type;
if ($this->l10n() && $this->loopL10n()) {
$locales = $this->translator()->availableLocales();
$outputId = $prop->{$getter}();
foreach ($locales as $langCode) {
// Set a unique property output ID for each locale.
$prop->{$setter}($outputId.'_'.$langCode);
$prop->setLang($langCode);
yield $prop;
}
$GLOBALS['widget_template'] = '';
$prop->{$setter}($outputId);
} else {
yield $prop;
$GLOBALS['widget_template'] = '';
}
} | php | public function output()
{
$output = $this->outputType();
switch ($output) {
case static::PROPERTY_DISPLAY:
$type = $this->displayType();
$prop = $this->display();
$getter = 'displayId';
$setter = 'setDisplayId';
break;
case static::PROPERTY_CONTROL:
$type = $this->inputType();
$prop = $this->input();
$getter = 'inputId';
$setter = 'setInputId';
break;
}
$GLOBALS['widget_template'] = $type;
if ($this->l10n() && $this->loopL10n()) {
$locales = $this->translator()->availableLocales();
$outputId = $prop->{$getter}();
foreach ($locales as $langCode) {
// Set a unique property output ID for each locale.
$prop->{$setter}($outputId.'_'.$langCode);
$prop->setLang($langCode);
yield $prop;
}
$GLOBALS['widget_template'] = '';
$prop->{$setter}($outputId);
} else {
yield $prop;
$GLOBALS['widget_template'] = '';
}
} | [
"public",
"function",
"output",
"(",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"outputType",
"(",
")",
";",
"switch",
"(",
"$",
"output",
")",
"{",
"case",
"static",
"::",
"PROPERTY_DISPLAY",
":",
"$",
"type",
"=",
"$",
"this",
"->",
"displayType",
"(",
")",
";",
"$",
"prop",
"=",
"$",
"this",
"->",
"display",
"(",
")",
";",
"$",
"getter",
"=",
"'displayId'",
";",
"$",
"setter",
"=",
"'setDisplayId'",
";",
"break",
";",
"case",
"static",
"::",
"PROPERTY_CONTROL",
":",
"$",
"type",
"=",
"$",
"this",
"->",
"inputType",
"(",
")",
";",
"$",
"prop",
"=",
"$",
"this",
"->",
"input",
"(",
")",
";",
"$",
"getter",
"=",
"'inputId'",
";",
"$",
"setter",
"=",
"'setInputId'",
";",
"break",
";",
"}",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"$",
"type",
";",
"if",
"(",
"$",
"this",
"->",
"l10n",
"(",
")",
"&&",
"$",
"this",
"->",
"loopL10n",
"(",
")",
")",
"{",
"$",
"locales",
"=",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"availableLocales",
"(",
")",
";",
"$",
"outputId",
"=",
"$",
"prop",
"->",
"{",
"$",
"getter",
"}",
"(",
")",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"langCode",
")",
"{",
"// Set a unique property output ID for each locale.",
"$",
"prop",
"->",
"{",
"$",
"setter",
"}",
"(",
"$",
"outputId",
".",
"'_'",
".",
"$",
"langCode",
")",
";",
"$",
"prop",
"->",
"setLang",
"(",
"$",
"langCode",
")",
";",
"yield",
"$",
"prop",
";",
"}",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"''",
";",
"$",
"prop",
"->",
"{",
"$",
"setter",
"}",
"(",
"$",
"outputId",
")",
";",
"}",
"else",
"{",
"yield",
"$",
"prop",
";",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"''",
";",
"}",
"}"
]
| Yield the property output.
Either a display property or a form control property.
@return PropertyInputInterface|PropertyDisplayInterface | [
"Yield",
"the",
"property",
"output",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1109-L1148 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setDependencies | protected function setDependencies(Container $container)
{
parent::setDependencies($container);
$this->setView($container['view']);
$this->setPropertyFactory($container['property/factory']);
$this->setPropertyInputFactory($container['property/input/factory']);
$this->setPropertyDisplayFactory($container['property/display/factory']);
} | php | protected function setDependencies(Container $container)
{
parent::setDependencies($container);
$this->setView($container['view']);
$this->setPropertyFactory($container['property/factory']);
$this->setPropertyInputFactory($container['property/input/factory']);
$this->setPropertyDisplayFactory($container['property/display/factory']);
} | [
"protected",
"function",
"setDependencies",
"(",
"Container",
"$",
"container",
")",
"{",
"parent",
"::",
"setDependencies",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setView",
"(",
"$",
"container",
"[",
"'view'",
"]",
")",
";",
"$",
"this",
"->",
"setPropertyFactory",
"(",
"$",
"container",
"[",
"'property/factory'",
"]",
")",
";",
"$",
"this",
"->",
"setPropertyInputFactory",
"(",
"$",
"container",
"[",
"'property/input/factory'",
"]",
")",
";",
"$",
"this",
"->",
"setPropertyDisplayFactory",
"(",
"$",
"container",
"[",
"'property/display/factory'",
"]",
")",
";",
"}"
]
| Set the widget's dependencies.
@param Container $container Service container.
@return void | [
"Set",
"the",
"widget",
"s",
"dependencies",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1156-L1164 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.resolveOutputType | protected function resolveOutputType($type)
{
if ($this->propertyInputFactory()->isResolvable($type)) {
$this->setInputType($type);
return static::PROPERTY_CONTROL;
} elseif ($this->propertyDisplayFactory()->isResolvable($type)) {
$this->setDisplayType($type);
return static::PROPERTY_DISPLAY;
} else {
throw new InvalidArgumentException(sprintf(
'Invalid form property output type, received %s',
is_object($type) ? get_class($type) : gettype($type)
));
}
} | php | protected function resolveOutputType($type)
{
if ($this->propertyInputFactory()->isResolvable($type)) {
$this->setInputType($type);
return static::PROPERTY_CONTROL;
} elseif ($this->propertyDisplayFactory()->isResolvable($type)) {
$this->setDisplayType($type);
return static::PROPERTY_DISPLAY;
} else {
throw new InvalidArgumentException(sprintf(
'Invalid form property output type, received %s',
is_object($type) ? get_class($type) : gettype($type)
));
}
} | [
"protected",
"function",
"resolveOutputType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"propertyInputFactory",
"(",
")",
"->",
"isResolvable",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"setInputType",
"(",
"$",
"type",
")",
";",
"return",
"static",
"::",
"PROPERTY_CONTROL",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"propertyDisplayFactory",
"(",
")",
"->",
"isResolvable",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"setDisplayType",
"(",
"$",
"type",
")",
";",
"return",
"static",
"::",
"PROPERTY_DISPLAY",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid form property output type, received %s'",
",",
"is_object",
"(",
"$",
"type",
")",
"?",
"get_class",
"(",
"$",
"type",
")",
":",
"gettype",
"(",
"$",
"type",
")",
")",
")",
";",
"}",
"}"
]
| Resolve the property output type.
Note: The "input_type" or "display_type" will be set
if the output type is a valid output property.
@param string $type The input or display property type.
@throws InvalidArgumentException If the property output type is invalid.
@return string Returns either "input" or "display". | [
"Resolve",
"the",
"property",
"output",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1215-L1229 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.setCoreData | private function setCoreData(array $data)
{
if (isset($data['input_type'])) {
$this->setInputType($data['input_type']);
}
if (isset($data['display_type'])) {
$this->setDisplayType($data['display_type']);
}
if (isset($data['property_type'])) {
$this->setPropertyType($data['property_type']);
}
if (isset($data['output_type'])) {
$this->setOutputType($data['output_type']);
}
if (isset($data['type'])) {
$this->setType($data['type']);
}
return $data;
} | php | private function setCoreData(array $data)
{
if (isset($data['input_type'])) {
$this->setInputType($data['input_type']);
}
if (isset($data['display_type'])) {
$this->setDisplayType($data['display_type']);
}
if (isset($data['property_type'])) {
$this->setPropertyType($data['property_type']);
}
if (isset($data['output_type'])) {
$this->setOutputType($data['output_type']);
}
if (isset($data['type'])) {
$this->setType($data['type']);
}
return $data;
} | [
"private",
"function",
"setCoreData",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'input_type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setInputType",
"(",
"$",
"data",
"[",
"'input_type'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'display_type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setDisplayType",
"(",
"$",
"data",
"[",
"'display_type'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'property_type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setPropertyType",
"(",
"$",
"data",
"[",
"'property_type'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'output_type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setOutputType",
"(",
"$",
"data",
"[",
"'output_type'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setType",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Set the core data for the widget and property's first.
@param array $data The widget and property data.
@return array The widget and property data. | [
"Set",
"the",
"core",
"data",
"for",
"the",
"widget",
"and",
"property",
"s",
"first",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1315-L1338 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.resolveInputType | private function resolveInputType()
{
$type = null;
/** Attempt input type resolution without instantiating the property, at first. */
$metadata = $this->propertyData();
if ($metadata) {
if (isset($metadata['hidden']) && $metadata['hidden']) {
$type = static::HIDDEN_FORM_CONTROL;
}
if (!$type && isset($metadata['input_type'])) {
$type = $metadata['input_type'];
}
}
if ($this->propertyType || $this->property) {
$property = $this->property();
$metadata = $property->metadata();
if ($property->hidden()) {
$type = static::HIDDEN_FORM_CONTROL;
}
if (!$type && isset($metadata['input_type'])) {
$type = $metadata['input_type'];
}
if (!$type && isset($metadata['admin']['input_type'])) {
$type = $metadata['admin']['input_type'];
}
}
if (!$type) {
$type = static::DEFAULT_FORM_CONTROL;
}
return $type;
} | php | private function resolveInputType()
{
$type = null;
/** Attempt input type resolution without instantiating the property, at first. */
$metadata = $this->propertyData();
if ($metadata) {
if (isset($metadata['hidden']) && $metadata['hidden']) {
$type = static::HIDDEN_FORM_CONTROL;
}
if (!$type && isset($metadata['input_type'])) {
$type = $metadata['input_type'];
}
}
if ($this->propertyType || $this->property) {
$property = $this->property();
$metadata = $property->metadata();
if ($property->hidden()) {
$type = static::HIDDEN_FORM_CONTROL;
}
if (!$type && isset($metadata['input_type'])) {
$type = $metadata['input_type'];
}
if (!$type && isset($metadata['admin']['input_type'])) {
$type = $metadata['admin']['input_type'];
}
}
if (!$type) {
$type = static::DEFAULT_FORM_CONTROL;
}
return $type;
} | [
"private",
"function",
"resolveInputType",
"(",
")",
"{",
"$",
"type",
"=",
"null",
";",
"/** Attempt input type resolution without instantiating the property, at first. */",
"$",
"metadata",
"=",
"$",
"this",
"->",
"propertyData",
"(",
")",
";",
"if",
"(",
"$",
"metadata",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'hidden'",
"]",
")",
"&&",
"$",
"metadata",
"[",
"'hidden'",
"]",
")",
"{",
"$",
"type",
"=",
"static",
"::",
"HIDDEN_FORM_CONTROL",
";",
"}",
"if",
"(",
"!",
"$",
"type",
"&&",
"isset",
"(",
"$",
"metadata",
"[",
"'input_type'",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"metadata",
"[",
"'input_type'",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"propertyType",
"||",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"metadata",
"=",
"$",
"property",
"->",
"metadata",
"(",
")",
";",
"if",
"(",
"$",
"property",
"->",
"hidden",
"(",
")",
")",
"{",
"$",
"type",
"=",
"static",
"::",
"HIDDEN_FORM_CONTROL",
";",
"}",
"if",
"(",
"!",
"$",
"type",
"&&",
"isset",
"(",
"$",
"metadata",
"[",
"'input_type'",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"metadata",
"[",
"'input_type'",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"type",
"&&",
"isset",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
"[",
"'input_type'",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"metadata",
"[",
"'admin'",
"]",
"[",
"'input_type'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"static",
"::",
"DEFAULT_FORM_CONTROL",
";",
"}",
"return",
"$",
"type",
";",
"}"
]
| Resolve the property control type.
@return string | [
"Resolve",
"the",
"property",
"control",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1345-L1383 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.resolveDisplayType | private function resolveDisplayType()
{
$type = null;
/** Attempt display type resolution without instantiating the property, at first. */
$metadata = $this->propertyData();
if ($metadata) {
if (isset($metadata['display_type'])) {
$type = $metadata['display_type'];
}
}
if ($this->propertyType || $this->property) {
$type = $this->property()->displayType();
}
return $type;
} | php | private function resolveDisplayType()
{
$type = null;
/** Attempt display type resolution without instantiating the property, at first. */
$metadata = $this->propertyData();
if ($metadata) {
if (isset($metadata['display_type'])) {
$type = $metadata['display_type'];
}
}
if ($this->propertyType || $this->property) {
$type = $this->property()->displayType();
}
return $type;
} | [
"private",
"function",
"resolveDisplayType",
"(",
")",
"{",
"$",
"type",
"=",
"null",
";",
"/** Attempt display type resolution without instantiating the property, at first. */",
"$",
"metadata",
"=",
"$",
"this",
"->",
"propertyData",
"(",
")",
";",
"if",
"(",
"$",
"metadata",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'display_type'",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"metadata",
"[",
"'display_type'",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"propertyType",
"||",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"property",
"(",
")",
"->",
"displayType",
"(",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
]
| Resolve the property display type.
@return string | [
"Resolve",
"the",
"property",
"display",
"type",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1390-L1407 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.createProperty | private function createProperty()
{
$propType = $this->propertyType();
if (empty($propType)) {
$ident = $this->propertyIdent();
if ($ident && is_string($ident)) {
$message = sprintf('Missing property type for property "%s"', $ident);
} else {
$message = sprintf('Missing property type');
}
throw new UnexpectedValueException($message);
}
$prop = $this->propertyFactory()->create($propType);
$prop->setIdent($this->propertyIdent());
$prop->setData($this->propertyData());
return $prop;
} | php | private function createProperty()
{
$propType = $this->propertyType();
if (empty($propType)) {
$ident = $this->propertyIdent();
if ($ident && is_string($ident)) {
$message = sprintf('Missing property type for property "%s"', $ident);
} else {
$message = sprintf('Missing property type');
}
throw new UnexpectedValueException($message);
}
$prop = $this->propertyFactory()->create($propType);
$prop->setIdent($this->propertyIdent());
$prop->setData($this->propertyData());
return $prop;
} | [
"private",
"function",
"createProperty",
"(",
")",
"{",
"$",
"propType",
"=",
"$",
"this",
"->",
"propertyType",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"propType",
")",
")",
"{",
"$",
"ident",
"=",
"$",
"this",
"->",
"propertyIdent",
"(",
")",
";",
"if",
"(",
"$",
"ident",
"&&",
"is_string",
"(",
"$",
"ident",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Missing property type for property \"%s\"'",
",",
"$",
"ident",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Missing property type'",
")",
";",
"}",
"throw",
"new",
"UnexpectedValueException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"prop",
"=",
"$",
"this",
"->",
"propertyFactory",
"(",
")",
"->",
"create",
"(",
"$",
"propType",
")",
";",
"$",
"prop",
"->",
"setIdent",
"(",
"$",
"this",
"->",
"propertyIdent",
"(",
")",
")",
";",
"$",
"prop",
"->",
"setData",
"(",
"$",
"this",
"->",
"propertyData",
"(",
")",
")",
";",
"return",
"$",
"prop",
";",
"}"
]
| Create the widget's model property from the property's dataset.
@throws UnexpectedValueException If the property type is missing.
@return PropertyInterface | [
"Create",
"the",
"widget",
"s",
"model",
"property",
"from",
"the",
"property",
"s",
"dataset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1416-L1435 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.createInputProperty | private function createInputProperty()
{
$prop = $this->property();
$type = $this->inputType();
$input = $this->propertyInputFactory()->create($type);
if ($this->formGroup() && ($input instanceof FormInputInterface)) {
$input->setFormGroup($this->formGroup());
}
if ($input instanceof ViewableInterface) {
$input->setViewController($this->viewController());
}
$metadata = $prop->metadata();
$data = $prop->data();
if (isset($metadata['admin'])) {
$data = array_replace_recursive($metadata['admin'], $data);
}
$input->setInputType($type);
$input->setProperty($prop);
$input->setPropertyVal($this->propertyVal());
$input->setData($data);
return $input;
} | php | private function createInputProperty()
{
$prop = $this->property();
$type = $this->inputType();
$input = $this->propertyInputFactory()->create($type);
if ($this->formGroup() && ($input instanceof FormInputInterface)) {
$input->setFormGroup($this->formGroup());
}
if ($input instanceof ViewableInterface) {
$input->setViewController($this->viewController());
}
$metadata = $prop->metadata();
$data = $prop->data();
if (isset($metadata['admin'])) {
$data = array_replace_recursive($metadata['admin'], $data);
}
$input->setInputType($type);
$input->setProperty($prop);
$input->setPropertyVal($this->propertyVal());
$input->setData($data);
return $input;
} | [
"private",
"function",
"createInputProperty",
"(",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"inputType",
"(",
")",
";",
"$",
"input",
"=",
"$",
"this",
"->",
"propertyInputFactory",
"(",
")",
"->",
"create",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"this",
"->",
"formGroup",
"(",
")",
"&&",
"(",
"$",
"input",
"instanceof",
"FormInputInterface",
")",
")",
"{",
"$",
"input",
"->",
"setFormGroup",
"(",
"$",
"this",
"->",
"formGroup",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"input",
"instanceof",
"ViewableInterface",
")",
"{",
"$",
"input",
"->",
"setViewController",
"(",
"$",
"this",
"->",
"viewController",
"(",
")",
")",
";",
"}",
"$",
"metadata",
"=",
"$",
"prop",
"->",
"metadata",
"(",
")",
";",
"$",
"data",
"=",
"$",
"prop",
"->",
"data",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"array_replace_recursive",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
",",
"$",
"data",
")",
";",
"}",
"$",
"input",
"->",
"setInputType",
"(",
"$",
"type",
")",
";",
"$",
"input",
"->",
"setProperty",
"(",
"$",
"prop",
")",
";",
"$",
"input",
"->",
"setPropertyVal",
"(",
"$",
"this",
"->",
"propertyVal",
"(",
")",
")",
";",
"$",
"input",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"return",
"$",
"input",
";",
"}"
]
| Create the widget's form control property.
@return PropertyInputInterface | [
"Create",
"the",
"widget",
"s",
"form",
"control",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1442-L1469 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormPropertyWidget.php | FormPropertyWidget.createDisplayProperty | private function createDisplayProperty()
{
$prop = $this->property();
$type = $this->displayType();
$display = $this->propertyDisplayFactory()->create($type);
if ($this->formGroup() && ($display instanceof FormInputInterface)) {
$display->setFormGroup($this->formGroup());
}
if ($display instanceof ViewableInterface) {
$display->setViewController($this->viewController());
}
$display->setDisplayType($type);
$display->setProperty($prop);
$display->setPropertyVal($this->propertyVal());
$display->setData($prop->data());
$metadata = $prop->metadata();
if (isset($metadata['admin'])) {
$display->setData($metadata['admin']);
}
return $display;
} | php | private function createDisplayProperty()
{
$prop = $this->property();
$type = $this->displayType();
$display = $this->propertyDisplayFactory()->create($type);
if ($this->formGroup() && ($display instanceof FormInputInterface)) {
$display->setFormGroup($this->formGroup());
}
if ($display instanceof ViewableInterface) {
$display->setViewController($this->viewController());
}
$display->setDisplayType($type);
$display->setProperty($prop);
$display->setPropertyVal($this->propertyVal());
$display->setData($prop->data());
$metadata = $prop->metadata();
if (isset($metadata['admin'])) {
$display->setData($metadata['admin']);
}
return $display;
} | [
"private",
"function",
"createDisplayProperty",
"(",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"property",
"(",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"displayType",
"(",
")",
";",
"$",
"display",
"=",
"$",
"this",
"->",
"propertyDisplayFactory",
"(",
")",
"->",
"create",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"this",
"->",
"formGroup",
"(",
")",
"&&",
"(",
"$",
"display",
"instanceof",
"FormInputInterface",
")",
")",
"{",
"$",
"display",
"->",
"setFormGroup",
"(",
"$",
"this",
"->",
"formGroup",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"display",
"instanceof",
"ViewableInterface",
")",
"{",
"$",
"display",
"->",
"setViewController",
"(",
"$",
"this",
"->",
"viewController",
"(",
")",
")",
";",
"}",
"$",
"display",
"->",
"setDisplayType",
"(",
"$",
"type",
")",
";",
"$",
"display",
"->",
"setProperty",
"(",
"$",
"prop",
")",
";",
"$",
"display",
"->",
"setPropertyVal",
"(",
"$",
"this",
"->",
"propertyVal",
"(",
")",
")",
";",
"$",
"display",
"->",
"setData",
"(",
"$",
"prop",
"->",
"data",
"(",
")",
")",
";",
"$",
"metadata",
"=",
"$",
"prop",
"->",
"metadata",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
")",
")",
"{",
"$",
"display",
"->",
"setData",
"(",
"$",
"metadata",
"[",
"'admin'",
"]",
")",
";",
"}",
"return",
"$",
"display",
";",
"}"
]
| Create the widget's display property.
@return PropertyDisplayInterface | [
"Create",
"the",
"widget",
"s",
"display",
"property",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormPropertyWidget.php#L1476-L1501 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/DualSelectInput.php | DualSelectInput.selectedChoices | public function selectedChoices()
{
$val = $this->parsedVal();
if ($val !== null) {
if (!$this->p()->multiple()) {
$val = [$val];
}
$choices = iterator_to_array(parent::choices());
/* Filter the all options down to those selected */
foreach ($val as $v) {
if (isset($choices[$v])) {
yield $choices[$v];
}
}
}
} | php | public function selectedChoices()
{
$val = $this->parsedVal();
if ($val !== null) {
if (!$this->p()->multiple()) {
$val = [$val];
}
$choices = iterator_to_array(parent::choices());
/* Filter the all options down to those selected */
foreach ($val as $v) {
if (isset($choices[$v])) {
yield $choices[$v];
}
}
}
} | [
"public",
"function",
"selectedChoices",
"(",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"parsedVal",
"(",
")",
";",
"if",
"(",
"$",
"val",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"p",
"(",
")",
"->",
"multiple",
"(",
")",
")",
"{",
"$",
"val",
"=",
"[",
"$",
"val",
"]",
";",
"}",
"$",
"choices",
"=",
"iterator_to_array",
"(",
"parent",
"::",
"choices",
"(",
")",
")",
";",
"/* Filter the all options down to those selected */",
"foreach",
"(",
"$",
"val",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"choices",
"[",
"$",
"v",
"]",
")",
")",
"{",
"yield",
"$",
"choices",
"[",
"$",
"v",
"]",
";",
"}",
"}",
"}",
"}"
]
| Retrieve the selected options.
@return Generator|array | [
"Retrieve",
"the",
"selected",
"options",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/DualSelectInput.php#L75-L93 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/DualSelectInput.php | DualSelectInput.reorderable | public function reorderable()
{
if ($this->reorderable === null) {
if (isset($this->dualSelectOptions['reorderable'])) {
$this->reorderable = boolval($this->dualSelectOptions['reorderable']);
} else {
$this->reorderable = false;
}
}
return $this->reorderable;
} | php | public function reorderable()
{
if ($this->reorderable === null) {
if (isset($this->dualSelectOptions['reorderable'])) {
$this->reorderable = boolval($this->dualSelectOptions['reorderable']);
} else {
$this->reorderable = false;
}
}
return $this->reorderable;
} | [
"public",
"function",
"reorderable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"reorderable",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dualSelectOptions",
"[",
"'reorderable'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reorderable",
"=",
"boolval",
"(",
"$",
"this",
"->",
"dualSelectOptions",
"[",
"'reorderable'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"reorderable",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"reorderable",
";",
"}"
]
| Determine if the right-side can be manually sorted.
@return boolean | [
"Determine",
"if",
"the",
"right",
"-",
"side",
"can",
"be",
"manually",
"sorted",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/DualSelectInput.php#L151-L162 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Input/DualSelectInput.php | DualSelectInput.dualSelectOptions | public function dualSelectOptions()
{
if ($this->dualSelectOptions === null) {
$this->dualSelectOptions = $this->defaultDualSelectOptions();
}
return $this->dualSelectOptions;
} | php | public function dualSelectOptions()
{
if ($this->dualSelectOptions === null) {
$this->dualSelectOptions = $this->defaultDualSelectOptions();
}
return $this->dualSelectOptions;
} | [
"public",
"function",
"dualSelectOptions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dualSelectOptions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"dualSelectOptions",
"=",
"$",
"this",
"->",
"defaultDualSelectOptions",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dualSelectOptions",
";",
"}"
]
| Retrieve the dual-select's options.
@return array | [
"Retrieve",
"the",
"dual",
"-",
"select",
"s",
"options",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/DualSelectInput.php#L313-L320 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Docs/Template/Object/DocTemplate.php | DocTemplate.headerMenu | public function headerMenu()
{
if ($this->headerMenu === null) {
$dashboardConfig = $this->dashboardConfig();
if (isset($dashboardConfig['secondary_menu'])) {
$this->headerMenu = $this->createHeaderMenu($dashboardConfig['secondary_menu']);
} else {
$this->headerMenu = $this->createHeaderMenu();
}
}
return $this->headerMenu;
} | php | public function headerMenu()
{
if ($this->headerMenu === null) {
$dashboardConfig = $this->dashboardConfig();
if (isset($dashboardConfig['secondary_menu'])) {
$this->headerMenu = $this->createHeaderMenu($dashboardConfig['secondary_menu']);
} else {
$this->headerMenu = $this->createHeaderMenu();
}
}
return $this->headerMenu;
} | [
"public",
"function",
"headerMenu",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"headerMenu",
"===",
"null",
")",
"{",
"$",
"dashboardConfig",
"=",
"$",
"this",
"->",
"dashboardConfig",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"dashboardConfig",
"[",
"'secondary_menu'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headerMenu",
"=",
"$",
"this",
"->",
"createHeaderMenu",
"(",
"$",
"dashboardConfig",
"[",
"'secondary_menu'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"headerMenu",
"=",
"$",
"this",
"->",
"createHeaderMenu",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"headerMenu",
";",
"}"
]
| Retrieve the header menu.
@return array | [
"Retrieve",
"the",
"header",
"menu",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Docs/Template/Object/DocTemplate.php#L44-L57 | train |
acquia/commerce-manager | modules/acm/src/Connector/APIWrapperFactory.php | APIWrapperFactory.get | public static function get(ContainerInterface $container) {
$test_mode = $container
->get('config.factory')
->get('acm.connector')
->get('test_mode');
if ($test_mode) {
return $container->get('acm.test_agent_api');
}
return $container->get('acm.agent_api');
} | php | public static function get(ContainerInterface $container) {
$test_mode = $container
->get('config.factory')
->get('acm.connector')
->get('test_mode');
if ($test_mode) {
return $container->get('acm.test_agent_api');
}
return $container->get('acm.agent_api');
} | [
"public",
"static",
"function",
"get",
"(",
"ContainerInterface",
"$",
"container",
")",
"{",
"$",
"test_mode",
"=",
"$",
"container",
"->",
"get",
"(",
"'config.factory'",
")",
"->",
"get",
"(",
"'acm.connector'",
")",
"->",
"get",
"(",
"'test_mode'",
")",
";",
"if",
"(",
"$",
"test_mode",
")",
"{",
"return",
"$",
"container",
"->",
"get",
"(",
"'acm.test_agent_api'",
")",
";",
"}",
"return",
"$",
"container",
"->",
"get",
"(",
"'acm.agent_api'",
")",
";",
"}"
]
| Creates an APIWrapperInterface object.
@param \Symfony\Component\DependencyInjection\ContainerInterface $container
The current service container.
@return \Drupal\acm\Connector\APIWrapperInterface
An api wrapper object. | [
"Creates",
"an",
"APIWrapperInterface",
"object",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Connector/APIWrapperFactory.php#L21-L32 | train |
acquia/commerce-manager | modules/acm/src/CommerceDashboardItemManager.php | CommerceDashboardItemManager.getDashboardItems | public function getDashboardItems() {
$instances = [];
$sortedDefinitions = [];
$definitions = $this->getDefinitions();
foreach ($definitions as $id => $definition) {
$sortedDefinitions[$definition['group']][$id] = $definition;
}
foreach ($sortedDefinitions as &$localSortedDefinitions) {
usort($localSortedDefinitions, [$this, 'sortPlugins']);
}
foreach ($sortedDefinitions as $group => $localDefinitions) {
foreach ($localDefinitions as $definition) {
$id = $definition['id'];
$instances[$group][$id] = $this->createInstance($id)->render();
}
}
return $instances;
} | php | public function getDashboardItems() {
$instances = [];
$sortedDefinitions = [];
$definitions = $this->getDefinitions();
foreach ($definitions as $id => $definition) {
$sortedDefinitions[$definition['group']][$id] = $definition;
}
foreach ($sortedDefinitions as &$localSortedDefinitions) {
usort($localSortedDefinitions, [$this, 'sortPlugins']);
}
foreach ($sortedDefinitions as $group => $localDefinitions) {
foreach ($localDefinitions as $definition) {
$id = $definition['id'];
$instances[$group][$id] = $this->createInstance($id)->render();
}
}
return $instances;
} | [
"public",
"function",
"getDashboardItems",
"(",
")",
"{",
"$",
"instances",
"=",
"[",
"]",
";",
"$",
"sortedDefinitions",
"=",
"[",
"]",
";",
"$",
"definitions",
"=",
"$",
"this",
"->",
"getDefinitions",
"(",
")",
";",
"foreach",
"(",
"$",
"definitions",
"as",
"$",
"id",
"=>",
"$",
"definition",
")",
"{",
"$",
"sortedDefinitions",
"[",
"$",
"definition",
"[",
"'group'",
"]",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"definition",
";",
"}",
"foreach",
"(",
"$",
"sortedDefinitions",
"as",
"&",
"$",
"localSortedDefinitions",
")",
"{",
"usort",
"(",
"$",
"localSortedDefinitions",
",",
"[",
"$",
"this",
",",
"'sortPlugins'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"sortedDefinitions",
"as",
"$",
"group",
"=>",
"$",
"localDefinitions",
")",
"{",
"foreach",
"(",
"$",
"localDefinitions",
"as",
"$",
"definition",
")",
"{",
"$",
"id",
"=",
"$",
"definition",
"[",
"'id'",
"]",
";",
"$",
"instances",
"[",
"$",
"group",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"createInstance",
"(",
"$",
"id",
")",
"->",
"render",
"(",
")",
";",
"}",
"}",
"return",
"$",
"instances",
";",
"}"
]
| Creates pre-configured instances of all plugins.
@return \Drupal\acm\CommerceDashboardItemInterface[][]
An array of fully configured plugin instances.
@throws \Drupal\Component\Plugin\Exception\PluginException
If an instance cannot be created, such as if the ID is invalid. | [
"Creates",
"pre",
"-",
"configured",
"instances",
"of",
"all",
"plugins",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/CommerceDashboardItemManager.php#L48-L69 | train |
acquia/commerce-manager | modules/acm_sku/src/Entity/SKU.php | SKU.loadFromSku | public static function loadFromSku($sku, $langcode = '', $log_not_found = TRUE, $create_translation = FALSE) {
$skus_static_cache = &drupal_static(__FUNCTION__, []);
$is_multilingual = \Drupal::languageManager()->isMultilingual();
if ($is_multilingual && empty($langcode)) {
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
}
$static_cache_sku_identifier = $sku . ':' . $langcode;
// Check if data is available in static cache, return from there.
// If create translation is true, it means we are doing product sync.
// For this case we don't want to use any static cache.
if (isset($skus_static_cache[$static_cache_sku_identifier]) && !$create_translation) {
return $skus_static_cache[$static_cache_sku_identifier];
}
$storage = \Drupal::entityTypeManager()->getStorage('acm_sku');
$skus = $storage->loadByProperties(['sku' => $sku]);
if (count($skus) == 0) {
// We don't log the error while doing sync.
if ($log_not_found) {
\Drupal::logger('acm_sku')->error('No SKU found for @sku.', ['@sku' => $sku]);
}
return NULL;
}
$sku_entity = reset($skus);
// Sanity check.
if (!($sku_entity instanceof SKUInterface)) {
return NULL;
}
// Now discard all skus in other languages if there is more than one.
if ($is_multilingual && count($skus) > 1) {
// Get rid of undesired languages. Later the first sku is picked up.
foreach ($skus as $key => $skuEntity) {
if ($skuEntity->language()->getId() != $langcode) {
unset($skus[$key]);
}
}
}
// Now test if there is still more than one sku found.
// Noting for multiple entries, we just log the error
// and continue with first sku.
if (count($skus) > 1) {
\Drupal::logger('acm_sku')->error('Duplicate SKUs found while loading for @sku.', ['@sku' => $sku]);
}
if ($is_multilingual) {
if ($sku_entity->hasTranslation($langcode)) {
$sku_entity = $sku_entity->getTranslation($langcode);
// Set value in static variable.
// We set in static cache only for proper case, when returning different
// language or creating translation we can avoid static cache.
$skus_static_cache[$static_cache_sku_identifier] = $sku_entity;
}
elseif ($create_translation) {
$sku_entity = $sku_entity->addTranslation($langcode, ['sku' => $sku]);
}
// We will continue execution with available translation and just log
// a message. During sync we say don't log messages.
elseif ($log_not_found) {
\Drupal::logger('acm_sku')->error('SKU translation not found of @sku for @langcode', ['@sku' => $sku, '@langcode' => $langcode]);
}
}
else {
// Set value in static variable directly if not a multi-lingual site.
$skus_static_cache[$static_cache_sku_identifier] = $sku_entity;
}
return $sku_entity;
} | php | public static function loadFromSku($sku, $langcode = '', $log_not_found = TRUE, $create_translation = FALSE) {
$skus_static_cache = &drupal_static(__FUNCTION__, []);
$is_multilingual = \Drupal::languageManager()->isMultilingual();
if ($is_multilingual && empty($langcode)) {
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
}
$static_cache_sku_identifier = $sku . ':' . $langcode;
// Check if data is available in static cache, return from there.
// If create translation is true, it means we are doing product sync.
// For this case we don't want to use any static cache.
if (isset($skus_static_cache[$static_cache_sku_identifier]) && !$create_translation) {
return $skus_static_cache[$static_cache_sku_identifier];
}
$storage = \Drupal::entityTypeManager()->getStorage('acm_sku');
$skus = $storage->loadByProperties(['sku' => $sku]);
if (count($skus) == 0) {
// We don't log the error while doing sync.
if ($log_not_found) {
\Drupal::logger('acm_sku')->error('No SKU found for @sku.', ['@sku' => $sku]);
}
return NULL;
}
$sku_entity = reset($skus);
// Sanity check.
if (!($sku_entity instanceof SKUInterface)) {
return NULL;
}
// Now discard all skus in other languages if there is more than one.
if ($is_multilingual && count($skus) > 1) {
// Get rid of undesired languages. Later the first sku is picked up.
foreach ($skus as $key => $skuEntity) {
if ($skuEntity->language()->getId() != $langcode) {
unset($skus[$key]);
}
}
}
// Now test if there is still more than one sku found.
// Noting for multiple entries, we just log the error
// and continue with first sku.
if (count($skus) > 1) {
\Drupal::logger('acm_sku')->error('Duplicate SKUs found while loading for @sku.', ['@sku' => $sku]);
}
if ($is_multilingual) {
if ($sku_entity->hasTranslation($langcode)) {
$sku_entity = $sku_entity->getTranslation($langcode);
// Set value in static variable.
// We set in static cache only for proper case, when returning different
// language or creating translation we can avoid static cache.
$skus_static_cache[$static_cache_sku_identifier] = $sku_entity;
}
elseif ($create_translation) {
$sku_entity = $sku_entity->addTranslation($langcode, ['sku' => $sku]);
}
// We will continue execution with available translation and just log
// a message. During sync we say don't log messages.
elseif ($log_not_found) {
\Drupal::logger('acm_sku')->error('SKU translation not found of @sku for @langcode', ['@sku' => $sku, '@langcode' => $langcode]);
}
}
else {
// Set value in static variable directly if not a multi-lingual site.
$skus_static_cache[$static_cache_sku_identifier] = $sku_entity;
}
return $sku_entity;
} | [
"public",
"static",
"function",
"loadFromSku",
"(",
"$",
"sku",
",",
"$",
"langcode",
"=",
"''",
",",
"$",
"log_not_found",
"=",
"TRUE",
",",
"$",
"create_translation",
"=",
"FALSE",
")",
"{",
"$",
"skus_static_cache",
"=",
"&",
"drupal_static",
"(",
"__FUNCTION__",
",",
"[",
"]",
")",
";",
"$",
"is_multilingual",
"=",
"\\",
"Drupal",
"::",
"languageManager",
"(",
")",
"->",
"isMultilingual",
"(",
")",
";",
"if",
"(",
"$",
"is_multilingual",
"&&",
"empty",
"(",
"$",
"langcode",
")",
")",
"{",
"$",
"langcode",
"=",
"\\",
"Drupal",
"::",
"languageManager",
"(",
")",
"->",
"getCurrentLanguage",
"(",
")",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"static_cache_sku_identifier",
"=",
"$",
"sku",
".",
"':'",
".",
"$",
"langcode",
";",
"// Check if data is available in static cache, return from there.",
"// If create translation is true, it means we are doing product sync.",
"// For this case we don't want to use any static cache.",
"if",
"(",
"isset",
"(",
"$",
"skus_static_cache",
"[",
"$",
"static_cache_sku_identifier",
"]",
")",
"&&",
"!",
"$",
"create_translation",
")",
"{",
"return",
"$",
"skus_static_cache",
"[",
"$",
"static_cache_sku_identifier",
"]",
";",
"}",
"$",
"storage",
"=",
"\\",
"Drupal",
"::",
"entityTypeManager",
"(",
")",
"->",
"getStorage",
"(",
"'acm_sku'",
")",
";",
"$",
"skus",
"=",
"$",
"storage",
"->",
"loadByProperties",
"(",
"[",
"'sku'",
"=>",
"$",
"sku",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"skus",
")",
"==",
"0",
")",
"{",
"// We don't log the error while doing sync.",
"if",
"(",
"$",
"log_not_found",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"error",
"(",
"'No SKU found for @sku.'",
",",
"[",
"'@sku'",
"=>",
"$",
"sku",
"]",
")",
";",
"}",
"return",
"NULL",
";",
"}",
"$",
"sku_entity",
"=",
"reset",
"(",
"$",
"skus",
")",
";",
"// Sanity check.",
"if",
"(",
"!",
"(",
"$",
"sku_entity",
"instanceof",
"SKUInterface",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"// Now discard all skus in other languages if there is more than one.",
"if",
"(",
"$",
"is_multilingual",
"&&",
"count",
"(",
"$",
"skus",
")",
">",
"1",
")",
"{",
"// Get rid of undesired languages. Later the first sku is picked up.",
"foreach",
"(",
"$",
"skus",
"as",
"$",
"key",
"=>",
"$",
"skuEntity",
")",
"{",
"if",
"(",
"$",
"skuEntity",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
"!=",
"$",
"langcode",
")",
"{",
"unset",
"(",
"$",
"skus",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"// Now test if there is still more than one sku found.",
"// Noting for multiple entries, we just log the error",
"// and continue with first sku.",
"if",
"(",
"count",
"(",
"$",
"skus",
")",
">",
"1",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"error",
"(",
"'Duplicate SKUs found while loading for @sku.'",
",",
"[",
"'@sku'",
"=>",
"$",
"sku",
"]",
")",
";",
"}",
"if",
"(",
"$",
"is_multilingual",
")",
"{",
"if",
"(",
"$",
"sku_entity",
"->",
"hasTranslation",
"(",
"$",
"langcode",
")",
")",
"{",
"$",
"sku_entity",
"=",
"$",
"sku_entity",
"->",
"getTranslation",
"(",
"$",
"langcode",
")",
";",
"// Set value in static variable.",
"// We set in static cache only for proper case, when returning different",
"// language or creating translation we can avoid static cache.",
"$",
"skus_static_cache",
"[",
"$",
"static_cache_sku_identifier",
"]",
"=",
"$",
"sku_entity",
";",
"}",
"elseif",
"(",
"$",
"create_translation",
")",
"{",
"$",
"sku_entity",
"=",
"$",
"sku_entity",
"->",
"addTranslation",
"(",
"$",
"langcode",
",",
"[",
"'sku'",
"=>",
"$",
"sku",
"]",
")",
";",
"}",
"// We will continue execution with available translation and just log",
"// a message. During sync we say don't log messages.",
"elseif",
"(",
"$",
"log_not_found",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"error",
"(",
"'SKU translation not found of @sku for @langcode'",
",",
"[",
"'@sku'",
"=>",
"$",
"sku",
",",
"'@langcode'",
"=>",
"$",
"langcode",
"]",
")",
";",
"}",
"}",
"else",
"{",
"// Set value in static variable directly if not a multi-lingual site.",
"$",
"skus_static_cache",
"[",
"$",
"static_cache_sku_identifier",
"]",
"=",
"$",
"sku_entity",
";",
"}",
"return",
"$",
"sku_entity",
";",
"}"
]
| Loads a SKU Entity from SKU.
@param string $sku
SKU to load.
@param string $langcode
Language code.
@param bool $log_not_found
Log errors when store not found. Can be false during sync.
@param bool $create_translation
Create translation and return if entity available but translation is not.
@return SKU|null
Found SKU
@throws \Exception | [
"Loads",
"a",
"SKU",
"Entity",
"from",
"SKU",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Entity/SKU.php#L101-L178 | train |
acquia/commerce-manager | modules/acm_sku/src/Entity/SKU.php | SKU.getThumbnail | public function getThumbnail() {
$media = $this->getMedia();
// We loop through all the media items and return the first image.
foreach ($media as $media_item) {
if (isset($media_item['media_type']) && $media_item['media_type'] == 'image') {
return $media_item;
}
}
return [];
} | php | public function getThumbnail() {
$media = $this->getMedia();
// We loop through all the media items and return the first image.
foreach ($media as $media_item) {
if (isset($media_item['media_type']) && $media_item['media_type'] == 'image') {
return $media_item;
}
}
return [];
} | [
"public",
"function",
"getThumbnail",
"(",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"getMedia",
"(",
")",
";",
"// We loop through all the media items and return the first image.",
"foreach",
"(",
"$",
"media",
"as",
"$",
"media_item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"media_item",
"[",
"'media_type'",
"]",
")",
"&&",
"$",
"media_item",
"[",
"'media_type'",
"]",
"==",
"'image'",
")",
"{",
"return",
"$",
"media_item",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
]
| Function to return first image from media files for a SKU.
@return array
Array of media files. | [
"Function",
"to",
"return",
"first",
"image",
"from",
"media",
"files",
"for",
"a",
"SKU",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Entity/SKU.php#L596-L607 | train |
acquia/commerce-manager | modules/acm_sku/src/Entity/SKU.php | SKU.getMedia | public function getMedia($download_media = TRUE, $reset = FALSE) {
if (!$reset && !empty($this->mediaData)) {
return $this->mediaData;
}
if ($media_data = $this->get('media')->getString()) {
$update_sku = FALSE;
$media_data = unserialize($media_data);
if (empty($media_data)) {
return [];
}
foreach ($media_data as &$data) {
// We don't want to show disabled images.
if (isset($data['disabled']) && $data['disabled']) {
continue;
}
$media_item = $this->processMediaItem($update_sku, $data, $download_media);
$this->mediaData[] = $media_item;
}
if ($update_sku) {
$this->get('media')->setValue(serialize($media_data));
$this->save();
}
}
return $this->mediaData;
} | php | public function getMedia($download_media = TRUE, $reset = FALSE) {
if (!$reset && !empty($this->mediaData)) {
return $this->mediaData;
}
if ($media_data = $this->get('media')->getString()) {
$update_sku = FALSE;
$media_data = unserialize($media_data);
if (empty($media_data)) {
return [];
}
foreach ($media_data as &$data) {
// We don't want to show disabled images.
if (isset($data['disabled']) && $data['disabled']) {
continue;
}
$media_item = $this->processMediaItem($update_sku, $data, $download_media);
$this->mediaData[] = $media_item;
}
if ($update_sku) {
$this->get('media')->setValue(serialize($media_data));
$this->save();
}
}
return $this->mediaData;
} | [
"public",
"function",
"getMedia",
"(",
"$",
"download_media",
"=",
"TRUE",
",",
"$",
"reset",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"reset",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"mediaData",
")",
")",
"{",
"return",
"$",
"this",
"->",
"mediaData",
";",
"}",
"if",
"(",
"$",
"media_data",
"=",
"$",
"this",
"->",
"get",
"(",
"'media'",
")",
"->",
"getString",
"(",
")",
")",
"{",
"$",
"update_sku",
"=",
"FALSE",
";",
"$",
"media_data",
"=",
"unserialize",
"(",
"$",
"media_data",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"media_data",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"media_data",
"as",
"&",
"$",
"data",
")",
"{",
"// We don't want to show disabled images.",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'disabled'",
"]",
")",
"&&",
"$",
"data",
"[",
"'disabled'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"media_item",
"=",
"$",
"this",
"->",
"processMediaItem",
"(",
"$",
"update_sku",
",",
"$",
"data",
",",
"$",
"download_media",
")",
";",
"$",
"this",
"->",
"mediaData",
"[",
"]",
"=",
"$",
"media_item",
";",
"}",
"if",
"(",
"$",
"update_sku",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'media'",
")",
"->",
"setValue",
"(",
"serialize",
"(",
"$",
"media_data",
")",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"mediaData",
";",
"}"
]
| Function to return media files for a SKU.
@param bool $download_media
Whether to download media or not.
@param bool $reset
Flag to reset cache and generate array again from serialized string.
@return array
Array of media files. | [
"Function",
"to",
"return",
"media",
"files",
"for",
"a",
"SKU",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Entity/SKU.php#L620-L652 | train |
acquia/commerce-manager | modules/acm_sku/src/Entity/SKU.php | SKU.processMediaItem | protected function processMediaItem(&$update_sku, array &$data, $download = FALSE) {
$media_item = $data;
// Processing is required only for media type image as of now.
if (isset($data['media_type']) && $data['media_type'] == 'image') {
if (!empty($data['fid'])) {
$file = File::load($data['fid']);
if (!($file instanceof FileInterface)) {
\Drupal::logger('acm_sku')->error('Empty file object for fid @fid on sku "@sku"', [
'@fid' => $data['fid'],
'@sku' => $this->getSku(),
]);
unset($data['fid']);
// Try to download again if download flag is set to true.
if ($download) {
return $this->processMediaItem($update_sku, $data, TRUE);
}
}
}
elseif ($download) {
try {
// Prepare the File object when we access it the first time.
$file = $this->downloadMediaImage($data);
$update_sku = TRUE;
}
catch (\Exception $e) {
\Drupal::logger('acm_sku')->error($e->getMessage());
return NULL;
}
}
if ($file instanceof FileInterface) {
$data['fid'] = $file->id();
$media_item['fid'] = $data['fid'];
$media_item['file'] = $file;
}
if (empty($data['label'])) {
$media_item['label'] = $this->label();
}
return $media_item;
}
} | php | protected function processMediaItem(&$update_sku, array &$data, $download = FALSE) {
$media_item = $data;
// Processing is required only for media type image as of now.
if (isset($data['media_type']) && $data['media_type'] == 'image') {
if (!empty($data['fid'])) {
$file = File::load($data['fid']);
if (!($file instanceof FileInterface)) {
\Drupal::logger('acm_sku')->error('Empty file object for fid @fid on sku "@sku"', [
'@fid' => $data['fid'],
'@sku' => $this->getSku(),
]);
unset($data['fid']);
// Try to download again if download flag is set to true.
if ($download) {
return $this->processMediaItem($update_sku, $data, TRUE);
}
}
}
elseif ($download) {
try {
// Prepare the File object when we access it the first time.
$file = $this->downloadMediaImage($data);
$update_sku = TRUE;
}
catch (\Exception $e) {
\Drupal::logger('acm_sku')->error($e->getMessage());
return NULL;
}
}
if ($file instanceof FileInterface) {
$data['fid'] = $file->id();
$media_item['fid'] = $data['fid'];
$media_item['file'] = $file;
}
if (empty($data['label'])) {
$media_item['label'] = $this->label();
}
return $media_item;
}
} | [
"protected",
"function",
"processMediaItem",
"(",
"&",
"$",
"update_sku",
",",
"array",
"&",
"$",
"data",
",",
"$",
"download",
"=",
"FALSE",
")",
"{",
"$",
"media_item",
"=",
"$",
"data",
";",
"// Processing is required only for media type image as of now.",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'media_type'",
"]",
")",
"&&",
"$",
"data",
"[",
"'media_type'",
"]",
"==",
"'image'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'fid'",
"]",
")",
")",
"{",
"$",
"file",
"=",
"File",
"::",
"load",
"(",
"$",
"data",
"[",
"'fid'",
"]",
")",
";",
"if",
"(",
"!",
"(",
"$",
"file",
"instanceof",
"FileInterface",
")",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"error",
"(",
"'Empty file object for fid @fid on sku \"@sku\"'",
",",
"[",
"'@fid'",
"=>",
"$",
"data",
"[",
"'fid'",
"]",
",",
"'@sku'",
"=>",
"$",
"this",
"->",
"getSku",
"(",
")",
",",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'fid'",
"]",
")",
";",
"// Try to download again if download flag is set to true.",
"if",
"(",
"$",
"download",
")",
"{",
"return",
"$",
"this",
"->",
"processMediaItem",
"(",
"$",
"update_sku",
",",
"$",
"data",
",",
"TRUE",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"download",
")",
"{",
"try",
"{",
"// Prepare the File object when we access it the first time.",
"$",
"file",
"=",
"$",
"this",
"->",
"downloadMediaImage",
"(",
"$",
"data",
")",
";",
"$",
"update_sku",
"=",
"TRUE",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"NULL",
";",
"}",
"}",
"if",
"(",
"$",
"file",
"instanceof",
"FileInterface",
")",
"{",
"$",
"data",
"[",
"'fid'",
"]",
"=",
"$",
"file",
"->",
"id",
"(",
")",
";",
"$",
"media_item",
"[",
"'fid'",
"]",
"=",
"$",
"data",
"[",
"'fid'",
"]",
";",
"$",
"media_item",
"[",
"'file'",
"]",
"=",
"$",
"file",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"media_item",
"[",
"'label'",
"]",
"=",
"$",
"this",
"->",
"label",
"(",
")",
";",
"}",
"return",
"$",
"media_item",
";",
"}",
"}"
]
| Function to get processed media item with File entity in array.
@param bool $update_sku
Flag to specify if SKU should be updated or not.
Update is done in parent function, here we only update the flag.
@param array $data
Media item array.
@param bool $download
Flag to specify if we should download missing images or not.
@return array|null
Processed media item or null if some error occurred. | [
"Function",
"to",
"get",
"processed",
"media",
"item",
"with",
"File",
"entity",
"in",
"array",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Entity/SKU.php#L668-L713 | train |
acquia/commerce-manager | modules/acm_sku/src/Entity/SKU.php | SKU.downloadMediaImage | protected function downloadMediaImage(array $data) {
// Preparing args for all info/error messages.
$args = ['@file' => $data['file'], '@sku_id' => $this->id()];
// Download the file contents.
try {
$file_data = \Drupal::httpClient()->get($data['file'])->getBody();
}
catch (RequestException $e) {
watchdog_exception('acq_commerce', $e);
}
// Check to ensure empty file is not saved in SKU.
if (empty($file_data)) {
throw new \Exception(new FormattableMarkup('Failed to download file "@file" for SKU id @sku_id.', $args));
}
// Get the path part in the url, remove hostname.
$path = parse_url($data['file'], PHP_URL_PATH);
// Remove slashes from start and end.
$path = trim($path, '/');
// Get the file name.
$file_name = basename($path);
// Prepare the directory path.
$directory = 'public://media/' . str_replace('/' . $file_name, '', $path);
// Prepare the directory.
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
// Save the file as file entity.
/** @var \Drupal\file\Entity\File $file */
if ($file = file_save_data($file_data, $directory . '/' . $file_name, FILE_EXISTS_REPLACE)) {
\Drupal::logger('acm_sku')
->debug('File @url downloaded to @file for SKU @sku',
[
'@url' => $data['file'],
'@file' => $file->id(),
'@sku' => $this->id(),
]);
return $file;
}
else {
throw new \Exception(new FormattableMarkup('Failed to save file "@file" for SKU id @sku_id.', $args));
}
} | php | protected function downloadMediaImage(array $data) {
// Preparing args for all info/error messages.
$args = ['@file' => $data['file'], '@sku_id' => $this->id()];
// Download the file contents.
try {
$file_data = \Drupal::httpClient()->get($data['file'])->getBody();
}
catch (RequestException $e) {
watchdog_exception('acq_commerce', $e);
}
// Check to ensure empty file is not saved in SKU.
if (empty($file_data)) {
throw new \Exception(new FormattableMarkup('Failed to download file "@file" for SKU id @sku_id.', $args));
}
// Get the path part in the url, remove hostname.
$path = parse_url($data['file'], PHP_URL_PATH);
// Remove slashes from start and end.
$path = trim($path, '/');
// Get the file name.
$file_name = basename($path);
// Prepare the directory path.
$directory = 'public://media/' . str_replace('/' . $file_name, '', $path);
// Prepare the directory.
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
// Save the file as file entity.
/** @var \Drupal\file\Entity\File $file */
if ($file = file_save_data($file_data, $directory . '/' . $file_name, FILE_EXISTS_REPLACE)) {
\Drupal::logger('acm_sku')
->debug('File @url downloaded to @file for SKU @sku',
[
'@url' => $data['file'],
'@file' => $file->id(),
'@sku' => $this->id(),
]);
return $file;
}
else {
throw new \Exception(new FormattableMarkup('Failed to save file "@file" for SKU id @sku_id.', $args));
}
} | [
"protected",
"function",
"downloadMediaImage",
"(",
"array",
"$",
"data",
")",
"{",
"// Preparing args for all info/error messages.",
"$",
"args",
"=",
"[",
"'@file'",
"=>",
"$",
"data",
"[",
"'file'",
"]",
",",
"'@sku_id'",
"=>",
"$",
"this",
"->",
"id",
"(",
")",
"]",
";",
"// Download the file contents.",
"try",
"{",
"$",
"file_data",
"=",
"\\",
"Drupal",
"::",
"httpClient",
"(",
")",
"->",
"get",
"(",
"$",
"data",
"[",
"'file'",
"]",
")",
"->",
"getBody",
"(",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"watchdog_exception",
"(",
"'acq_commerce'",
",",
"$",
"e",
")",
";",
"}",
"// Check to ensure empty file is not saved in SKU.",
"if",
"(",
"empty",
"(",
"$",
"file_data",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"new",
"FormattableMarkup",
"(",
"'Failed to download file \"@file\" for SKU id @sku_id.'",
",",
"$",
"args",
")",
")",
";",
"}",
"// Get the path part in the url, remove hostname.",
"$",
"path",
"=",
"parse_url",
"(",
"$",
"data",
"[",
"'file'",
"]",
",",
"PHP_URL_PATH",
")",
";",
"// Remove slashes from start and end.",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"// Get the file name.",
"$",
"file_name",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"// Prepare the directory path.",
"$",
"directory",
"=",
"'public://media/'",
".",
"str_replace",
"(",
"'/'",
".",
"$",
"file_name",
",",
"''",
",",
"$",
"path",
")",
";",
"// Prepare the directory.",
"file_prepare_directory",
"(",
"$",
"directory",
",",
"FILE_CREATE_DIRECTORY",
")",
";",
"// Save the file as file entity.",
"/** @var \\Drupal\\file\\Entity\\File $file */",
"if",
"(",
"$",
"file",
"=",
"file_save_data",
"(",
"$",
"file_data",
",",
"$",
"directory",
".",
"'/'",
".",
"$",
"file_name",
",",
"FILE_EXISTS_REPLACE",
")",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"debug",
"(",
"'File @url downloaded to @file for SKU @sku'",
",",
"[",
"'@url'",
"=>",
"$",
"data",
"[",
"'file'",
"]",
",",
"'@file'",
"=>",
"$",
"file",
"->",
"id",
"(",
")",
",",
"'@sku'",
"=>",
"$",
"this",
"->",
"id",
"(",
")",
",",
"]",
")",
";",
"return",
"$",
"file",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"new",
"FormattableMarkup",
"(",
"'Failed to save file \"@file\" for SKU id @sku_id.'",
",",
"$",
"args",
")",
")",
";",
"}",
"}"
]
| Function to save image file into public dir.
@param array $data
File data.
@return \Drupal\file\Entity\File
File object.
@throws \Exception
If media fails to be downloaded. | [
"Function",
"to",
"save",
"image",
"file",
"into",
"public",
"dir",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Entity/SKU.php#L727-L773 | train |
acquia/commerce-manager | modules/acm_cart/src/Cart.php | Cart.updateCartObject | public function updateCartObject($cart) {
if (isset($cart->customer_id)) {
$cart->customer_id = (string) $cart->customer_id;
}
// Some ecommerce backends, like hybris, don't save the billing like they
// do with shipping. So if a billing was set we don't want it to be
// overwritten when the API response comes back.
$current_billing = $this->getBilling();
if (!empty($current_billing) && empty($cart->billing)) {
$cart->billing = $current_billing;
}
if (isset($cart->carrier)) {
// We use it as array internally everywhere, even set as array.
$cart->carrier = (array) $cart->carrier;
// If carrier is with empty structure, we remove it.
if (empty($cart->carrier['carrier_code'])) {
unset($cart->carrier);
}
}
$this->cart = $cart;
$this->updateCartItemsCount();
} | php | public function updateCartObject($cart) {
if (isset($cart->customer_id)) {
$cart->customer_id = (string) $cart->customer_id;
}
// Some ecommerce backends, like hybris, don't save the billing like they
// do with shipping. So if a billing was set we don't want it to be
// overwritten when the API response comes back.
$current_billing = $this->getBilling();
if (!empty($current_billing) && empty($cart->billing)) {
$cart->billing = $current_billing;
}
if (isset($cart->carrier)) {
// We use it as array internally everywhere, even set as array.
$cart->carrier = (array) $cart->carrier;
// If carrier is with empty structure, we remove it.
if (empty($cart->carrier['carrier_code'])) {
unset($cart->carrier);
}
}
$this->cart = $cart;
$this->updateCartItemsCount();
} | [
"public",
"function",
"updateCartObject",
"(",
"$",
"cart",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cart",
"->",
"customer_id",
")",
")",
"{",
"$",
"cart",
"->",
"customer_id",
"=",
"(",
"string",
")",
"$",
"cart",
"->",
"customer_id",
";",
"}",
"// Some ecommerce backends, like hybris, don't save the billing like they",
"// do with shipping. So if a billing was set we don't want it to be",
"// overwritten when the API response comes back.",
"$",
"current_billing",
"=",
"$",
"this",
"->",
"getBilling",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"current_billing",
")",
"&&",
"empty",
"(",
"$",
"cart",
"->",
"billing",
")",
")",
"{",
"$",
"cart",
"->",
"billing",
"=",
"$",
"current_billing",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"cart",
"->",
"carrier",
")",
")",
"{",
"// We use it as array internally everywhere, even set as array.",
"$",
"cart",
"->",
"carrier",
"=",
"(",
"array",
")",
"$",
"cart",
"->",
"carrier",
";",
"// If carrier is with empty structure, we remove it.",
"if",
"(",
"empty",
"(",
"$",
"cart",
"->",
"carrier",
"[",
"'carrier_code'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"cart",
"->",
"carrier",
")",
";",
"}",
"}",
"$",
"this",
"->",
"cart",
"=",
"$",
"cart",
";",
"$",
"this",
"->",
"updateCartItemsCount",
"(",
")",
";",
"}"
]
| Function to update cart object.
@param object $cart
The cart. | [
"Function",
"to",
"update",
"cart",
"object",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/Cart.php#L70-L95 | train |
acquia/commerce-manager | modules/acm_cart/src/Cart.php | Cart.updateCartItemsCount | public function updateCartItemsCount() {
$this->cartTotalCount = 0;
foreach ($this->items() as $item) {
$this->cartTotalCount += $item['qty'];
}
} | php | public function updateCartItemsCount() {
$this->cartTotalCount = 0;
foreach ($this->items() as $item) {
$this->cartTotalCount += $item['qty'];
}
} | [
"public",
"function",
"updateCartItemsCount",
"(",
")",
"{",
"$",
"this",
"->",
"cartTotalCount",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"cartTotalCount",
"+=",
"$",
"item",
"[",
"'qty'",
"]",
";",
"}",
"}"
]
| Calculate the cart items quantity. | [
"Calculate",
"the",
"cart",
"items",
"quantity",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/Cart.php#L333-L338 | train |
acquia/commerce-manager | modules/acm_cart/src/Cart.php | Cart.normalizeAddress | private function normalizeAddress($address) {
if (isset($address->extension)) {
if (!is_object($address->extension)) {
$anObject = (object) $address->extension;
$address->extension = $anObject;
}
}
return $address;
} | php | private function normalizeAddress($address) {
if (isset($address->extension)) {
if (!is_object($address->extension)) {
$anObject = (object) $address->extension;
$address->extension = $anObject;
}
}
return $address;
} | [
"private",
"function",
"normalizeAddress",
"(",
"$",
"address",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"address",
"->",
"extension",
")",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"address",
"->",
"extension",
")",
")",
"{",
"$",
"anObject",
"=",
"(",
"object",
")",
"$",
"address",
"->",
"extension",
";",
"$",
"address",
"->",
"extension",
"=",
"$",
"anObject",
";",
"}",
"}",
"return",
"$",
"address",
";",
"}"
]
| Address normalizer.
@param object $address
Object of address.
@return object
Normalized address. | [
"Address",
"normalizer",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/Cart.php#L360-L368 | train |
acquia/commerce-manager | modules/acm_sku/src/ProductOptionsManager.php | ProductOptionsManager.createProductOption | protected function createProductOption($langcode, $option_id, $option_value, $attribute_id, $attribute_code, $weight) {
if (strlen($option_value) == 0) {
$this->logger->warning('Got empty value while syncing production options: @data', [
'@data' => json_encode([
'langcode' => $langcode,
'option_id' => $option_id,
'attribute_id' => $attribute_id,
'attribute_code' => $attribute_code,
]),
]);
return NULL;
}
// Update the term if already available.
if ($term = $this->loadProductOptionByOptionId($attribute_code, $option_id, NULL, FALSE)) {
$save_term = FALSE;
// Save term even if weight changes.
if ($term->getWeight() != $weight) {
$save_term = TRUE;
}
if ($term->hasTranslation($langcode)) {
$term = $term->getTranslation($langcode);
// We won't allow editing name here, if required it must be done from
// Magento.
if ($term->getName() != $option_value) {
$term->setName($option_value);
$save_term = TRUE;
}
}
else {
$term = $term->addTranslation($langcode, []);
$term->setName($option_value);
$save_term = TRUE;
}
if ($save_term) {
$term->setWeight($weight);
$term->save();
}
}
else {
$term = $this->termStorage->create([
'vid' => self::PRODUCT_OPTIONS_VOCABULARY,
'langcode' => $langcode,
'name' => $option_value,
'weight' => $weight,
'field_sku_option_id' => $option_id,
'field_sku_attribute_id' => $attribute_id,
'field_sku_attribute_code' => $attribute_code,
]);
try {
$term->save();
}
catch (EntityStorageException $exception) {
$this->logger->critical('Product option "@option" wasn\'t saved. Try again later please.', ['@option' => $option_value]);
}
}
return $term;
} | php | protected function createProductOption($langcode, $option_id, $option_value, $attribute_id, $attribute_code, $weight) {
if (strlen($option_value) == 0) {
$this->logger->warning('Got empty value while syncing production options: @data', [
'@data' => json_encode([
'langcode' => $langcode,
'option_id' => $option_id,
'attribute_id' => $attribute_id,
'attribute_code' => $attribute_code,
]),
]);
return NULL;
}
// Update the term if already available.
if ($term = $this->loadProductOptionByOptionId($attribute_code, $option_id, NULL, FALSE)) {
$save_term = FALSE;
// Save term even if weight changes.
if ($term->getWeight() != $weight) {
$save_term = TRUE;
}
if ($term->hasTranslation($langcode)) {
$term = $term->getTranslation($langcode);
// We won't allow editing name here, if required it must be done from
// Magento.
if ($term->getName() != $option_value) {
$term->setName($option_value);
$save_term = TRUE;
}
}
else {
$term = $term->addTranslation($langcode, []);
$term->setName($option_value);
$save_term = TRUE;
}
if ($save_term) {
$term->setWeight($weight);
$term->save();
}
}
else {
$term = $this->termStorage->create([
'vid' => self::PRODUCT_OPTIONS_VOCABULARY,
'langcode' => $langcode,
'name' => $option_value,
'weight' => $weight,
'field_sku_option_id' => $option_id,
'field_sku_attribute_id' => $attribute_id,
'field_sku_attribute_code' => $attribute_code,
]);
try {
$term->save();
}
catch (EntityStorageException $exception) {
$this->logger->critical('Product option "@option" wasn\'t saved. Try again later please.', ['@option' => $option_value]);
}
}
return $term;
} | [
"protected",
"function",
"createProductOption",
"(",
"$",
"langcode",
",",
"$",
"option_id",
",",
"$",
"option_value",
",",
"$",
"attribute_id",
",",
"$",
"attribute_code",
",",
"$",
"weight",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"option_value",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"'Got empty value while syncing production options: @data'",
",",
"[",
"'@data'",
"=>",
"json_encode",
"(",
"[",
"'langcode'",
"=>",
"$",
"langcode",
",",
"'option_id'",
"=>",
"$",
"option_id",
",",
"'attribute_id'",
"=>",
"$",
"attribute_id",
",",
"'attribute_code'",
"=>",
"$",
"attribute_code",
",",
"]",
")",
",",
"]",
")",
";",
"return",
"NULL",
";",
"}",
"// Update the term if already available.",
"if",
"(",
"$",
"term",
"=",
"$",
"this",
"->",
"loadProductOptionByOptionId",
"(",
"$",
"attribute_code",
",",
"$",
"option_id",
",",
"NULL",
",",
"FALSE",
")",
")",
"{",
"$",
"save_term",
"=",
"FALSE",
";",
"// Save term even if weight changes.",
"if",
"(",
"$",
"term",
"->",
"getWeight",
"(",
")",
"!=",
"$",
"weight",
")",
"{",
"$",
"save_term",
"=",
"TRUE",
";",
"}",
"if",
"(",
"$",
"term",
"->",
"hasTranslation",
"(",
"$",
"langcode",
")",
")",
"{",
"$",
"term",
"=",
"$",
"term",
"->",
"getTranslation",
"(",
"$",
"langcode",
")",
";",
"// We won't allow editing name here, if required it must be done from",
"// Magento.",
"if",
"(",
"$",
"term",
"->",
"getName",
"(",
")",
"!=",
"$",
"option_value",
")",
"{",
"$",
"term",
"->",
"setName",
"(",
"$",
"option_value",
")",
";",
"$",
"save_term",
"=",
"TRUE",
";",
"}",
"}",
"else",
"{",
"$",
"term",
"=",
"$",
"term",
"->",
"addTranslation",
"(",
"$",
"langcode",
",",
"[",
"]",
")",
";",
"$",
"term",
"->",
"setName",
"(",
"$",
"option_value",
")",
";",
"$",
"save_term",
"=",
"TRUE",
";",
"}",
"if",
"(",
"$",
"save_term",
")",
"{",
"$",
"term",
"->",
"setWeight",
"(",
"$",
"weight",
")",
";",
"$",
"term",
"->",
"save",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"term",
"=",
"$",
"this",
"->",
"termStorage",
"->",
"create",
"(",
"[",
"'vid'",
"=>",
"self",
"::",
"PRODUCT_OPTIONS_VOCABULARY",
",",
"'langcode'",
"=>",
"$",
"langcode",
",",
"'name'",
"=>",
"$",
"option_value",
",",
"'weight'",
"=>",
"$",
"weight",
",",
"'field_sku_option_id'",
"=>",
"$",
"option_id",
",",
"'field_sku_attribute_id'",
"=>",
"$",
"attribute_id",
",",
"'field_sku_attribute_code'",
"=>",
"$",
"attribute_code",
",",
"]",
")",
";",
"try",
"{",
"$",
"term",
"->",
"save",
"(",
")",
";",
"}",
"catch",
"(",
"EntityStorageException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"'Product option \"@option\" wasn\\'t saved. Try again later please.'",
",",
"[",
"'@option'",
"=>",
"$",
"option_value",
"]",
")",
";",
"}",
"}",
"return",
"$",
"term",
";",
"}"
]
| Create product option if not available or update the name.
@param string $langcode
Lang code.
@param int $option_id
Option id.
@param string $option_value
Value (term name).
@param int $attribute_id
Attribute id.
@param string $attribute_code
Attribute code.
@param int $weight
Taxonomy term weight == attribute option sort order.
@return \Drupal\taxonomy\Entity\Term|null
Term object or null. | [
"Create",
"product",
"option",
"if",
"not",
"available",
"or",
"update",
"the",
"name",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductOptionsManager.php#L155-L218 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.showSidebarActions | public function showSidebarActions()
{
$actions = array_filter($this->sidebarActions(), function($action) {
return $action['active'] === true;
});
return count($actions) > 0;
} | php | public function showSidebarActions()
{
$actions = array_filter($this->sidebarActions(), function($action) {
return $action['active'] === true;
});
return count($actions) > 0;
} | [
"public",
"function",
"showSidebarActions",
"(",
")",
"{",
"$",
"actions",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"sidebarActions",
"(",
")",
",",
"function",
"(",
"$",
"action",
")",
"{",
"return",
"$",
"action",
"[",
"'active'",
"]",
"===",
"true",
";",
"}",
")",
";",
"return",
"count",
"(",
"$",
"actions",
")",
">",
"0",
";",
"}"
]
| Determine if the sidebar's actions should be shown.
@return boolean | [
"Determine",
"if",
"the",
"sidebar",
"s",
"actions",
"should",
"be",
"shown",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L331-L338 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.sidebarActions | public function sidebarActions()
{
if ($this->sidebarActions === null) {
$this->setSidebarActions([]);
}
if ($this->parsedSidebarActions === false) {
$this->parsedSidebarActions = true;
$this->sidebarActions = $this->createSidebarActions($this->sidebarActions);
}
return $this->sidebarActions;
} | php | public function sidebarActions()
{
if ($this->sidebarActions === null) {
$this->setSidebarActions([]);
}
if ($this->parsedSidebarActions === false) {
$this->parsedSidebarActions = true;
$this->sidebarActions = $this->createSidebarActions($this->sidebarActions);
}
return $this->sidebarActions;
} | [
"public",
"function",
"sidebarActions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sidebarActions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setSidebarActions",
"(",
"[",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"parsedSidebarActions",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"parsedSidebarActions",
"=",
"true",
";",
"$",
"this",
"->",
"sidebarActions",
"=",
"$",
"this",
"->",
"createSidebarActions",
"(",
"$",
"this",
"->",
"sidebarActions",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sidebarActions",
";",
"}"
]
| Retrieve the sidebar's actions.
@return array | [
"Retrieve",
"the",
"sidebar",
"s",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L345-L357 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.setSidebarActions | protected function setSidebarActions(array $actions)
{
$this->parsedSidebarActions = false;
$this->sidebarActions = $this->mergeActions($this->defaultSidebarActions(), $actions);
return $this;
} | php | protected function setSidebarActions(array $actions)
{
$this->parsedSidebarActions = false;
$this->sidebarActions = $this->mergeActions($this->defaultSidebarActions(), $actions);
return $this;
} | [
"protected",
"function",
"setSidebarActions",
"(",
"array",
"$",
"actions",
")",
"{",
"$",
"this",
"->",
"parsedSidebarActions",
"=",
"false",
";",
"$",
"this",
"->",
"sidebarActions",
"=",
"$",
"this",
"->",
"mergeActions",
"(",
"$",
"this",
"->",
"defaultSidebarActions",
"(",
")",
",",
"$",
"actions",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the sidebar's actions.
@param array $actions One or more actions.
@return FormSidebarWidget Chainable. | [
"Set",
"the",
"sidebar",
"s",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L365-L372 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.createSidebarActions | protected function createSidebarActions(array $actions)
{
$this->actionsPriority = $this->defaultActionPriority();
$sidebarActions = $this->parseAsSidebarActions($actions);
return $sidebarActions;
} | php | protected function createSidebarActions(array $actions)
{
$this->actionsPriority = $this->defaultActionPriority();
$sidebarActions = $this->parseAsSidebarActions($actions);
return $sidebarActions;
} | [
"protected",
"function",
"createSidebarActions",
"(",
"array",
"$",
"actions",
")",
"{",
"$",
"this",
"->",
"actionsPriority",
"=",
"$",
"this",
"->",
"defaultActionPriority",
"(",
")",
";",
"$",
"sidebarActions",
"=",
"$",
"this",
"->",
"parseAsSidebarActions",
"(",
"$",
"actions",
")",
";",
"return",
"$",
"sidebarActions",
";",
"}"
]
| Build the sidebar's actions.
Sidebar actions should come from the form settings defined by the "sidebars".
It is still possible to completly override those externally by setting the "actions"
with the {@see self::setSidebarActions()} method.
@param array $actions Actions to resolve.
@return array Sidebar actions. | [
"Build",
"the",
"sidebar",
"s",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L384-L391 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.parseAsSidebarActions | protected function parseAsSidebarActions(array $actions)
{
$sidebarActions = [];
foreach ($actions as $ident => $action) {
$ident = $this->parseActionIdent($ident, $action);
$action = $this->parseActionItem($action, $ident, true);
if (!isset($action['priority'])) {
$action['priority'] = $this->actionsPriority++;
}
if ($action['ident'] === 'view' && !$this->isObjViewable()) {
$action['active'] = false;
} elseif ($action['ident'] === 'save' && !$this->isObjSavable()) {
$action['active'] = false;
} elseif ($action['ident'] === 'reset' && !$this->isObjResettable()) {
$action['active'] = false;
} elseif ($action['ident'] === 'delete' && !$this->isObjDeletable()) {
$action['active'] = false;
}
if ($action['isSubmittable'] && !$this->isObjSavable()) {
$action['active'] = false;
}
if ($action['actions']) {
$action['actions'] = $this->parseAsSidebarActions($action['actions']);
$action['hasActions'] = !!array_filter($action['actions'], function ($action) {
return $action['active'];
});
}
if (isset($sidebarActions[$ident])) {
$hasPriority = ($action['priority'] > $sidebarActions[$ident]['priority']);
if ($hasPriority || $action['isSubmittable']) {
$sidebarActions[$ident] = array_replace($sidebarActions[$ident], $action);
} else {
$sidebarActions[$ident] = array_replace($action, $sidebarActions[$ident]);
}
} else {
$sidebarActions[$ident] = $action;
}
}
usort($sidebarActions, [ $this, 'sortActionsByPriority' ]);
while (($first = reset($sidebarActions)) && $first['isSeparator']) {
array_shift($sidebarActions);
}
while (($last = end($sidebarActions)) && $last['isSeparator']) {
array_pop($sidebarActions);
}
return $sidebarActions;
} | php | protected function parseAsSidebarActions(array $actions)
{
$sidebarActions = [];
foreach ($actions as $ident => $action) {
$ident = $this->parseActionIdent($ident, $action);
$action = $this->parseActionItem($action, $ident, true);
if (!isset($action['priority'])) {
$action['priority'] = $this->actionsPriority++;
}
if ($action['ident'] === 'view' && !$this->isObjViewable()) {
$action['active'] = false;
} elseif ($action['ident'] === 'save' && !$this->isObjSavable()) {
$action['active'] = false;
} elseif ($action['ident'] === 'reset' && !$this->isObjResettable()) {
$action['active'] = false;
} elseif ($action['ident'] === 'delete' && !$this->isObjDeletable()) {
$action['active'] = false;
}
if ($action['isSubmittable'] && !$this->isObjSavable()) {
$action['active'] = false;
}
if ($action['actions']) {
$action['actions'] = $this->parseAsSidebarActions($action['actions']);
$action['hasActions'] = !!array_filter($action['actions'], function ($action) {
return $action['active'];
});
}
if (isset($sidebarActions[$ident])) {
$hasPriority = ($action['priority'] > $sidebarActions[$ident]['priority']);
if ($hasPriority || $action['isSubmittable']) {
$sidebarActions[$ident] = array_replace($sidebarActions[$ident], $action);
} else {
$sidebarActions[$ident] = array_replace($action, $sidebarActions[$ident]);
}
} else {
$sidebarActions[$ident] = $action;
}
}
usort($sidebarActions, [ $this, 'sortActionsByPriority' ]);
while (($first = reset($sidebarActions)) && $first['isSeparator']) {
array_shift($sidebarActions);
}
while (($last = end($sidebarActions)) && $last['isSeparator']) {
array_pop($sidebarActions);
}
return $sidebarActions;
} | [
"protected",
"function",
"parseAsSidebarActions",
"(",
"array",
"$",
"actions",
")",
"{",
"$",
"sidebarActions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"ident",
"=>",
"$",
"action",
")",
"{",
"$",
"ident",
"=",
"$",
"this",
"->",
"parseActionIdent",
"(",
"$",
"ident",
",",
"$",
"action",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"parseActionItem",
"(",
"$",
"action",
",",
"$",
"ident",
",",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"action",
"[",
"'priority'",
"]",
")",
")",
"{",
"$",
"action",
"[",
"'priority'",
"]",
"=",
"$",
"this",
"->",
"actionsPriority",
"++",
";",
"}",
"if",
"(",
"$",
"action",
"[",
"'ident'",
"]",
"===",
"'view'",
"&&",
"!",
"$",
"this",
"->",
"isObjViewable",
"(",
")",
")",
"{",
"$",
"action",
"[",
"'active'",
"]",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"action",
"[",
"'ident'",
"]",
"===",
"'save'",
"&&",
"!",
"$",
"this",
"->",
"isObjSavable",
"(",
")",
")",
"{",
"$",
"action",
"[",
"'active'",
"]",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"action",
"[",
"'ident'",
"]",
"===",
"'reset'",
"&&",
"!",
"$",
"this",
"->",
"isObjResettable",
"(",
")",
")",
"{",
"$",
"action",
"[",
"'active'",
"]",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"action",
"[",
"'ident'",
"]",
"===",
"'delete'",
"&&",
"!",
"$",
"this",
"->",
"isObjDeletable",
"(",
")",
")",
"{",
"$",
"action",
"[",
"'active'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"action",
"[",
"'isSubmittable'",
"]",
"&&",
"!",
"$",
"this",
"->",
"isObjSavable",
"(",
")",
")",
"{",
"$",
"action",
"[",
"'active'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"action",
"[",
"'actions'",
"]",
")",
"{",
"$",
"action",
"[",
"'actions'",
"]",
"=",
"$",
"this",
"->",
"parseAsSidebarActions",
"(",
"$",
"action",
"[",
"'actions'",
"]",
")",
";",
"$",
"action",
"[",
"'hasActions'",
"]",
"=",
"!",
"!",
"array_filter",
"(",
"$",
"action",
"[",
"'actions'",
"]",
",",
"function",
"(",
"$",
"action",
")",
"{",
"return",
"$",
"action",
"[",
"'active'",
"]",
";",
"}",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
")",
")",
"{",
"$",
"hasPriority",
"=",
"(",
"$",
"action",
"[",
"'priority'",
"]",
">",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
"[",
"'priority'",
"]",
")",
";",
"if",
"(",
"$",
"hasPriority",
"||",
"$",
"action",
"[",
"'isSubmittable'",
"]",
")",
"{",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
"=",
"array_replace",
"(",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
",",
"$",
"action",
")",
";",
"}",
"else",
"{",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
"=",
"array_replace",
"(",
"$",
"action",
",",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"sidebarActions",
"[",
"$",
"ident",
"]",
"=",
"$",
"action",
";",
"}",
"}",
"usort",
"(",
"$",
"sidebarActions",
",",
"[",
"$",
"this",
",",
"'sortActionsByPriority'",
"]",
")",
";",
"while",
"(",
"(",
"$",
"first",
"=",
"reset",
"(",
"$",
"sidebarActions",
")",
")",
"&&",
"$",
"first",
"[",
"'isSeparator'",
"]",
")",
"{",
"array_shift",
"(",
"$",
"sidebarActions",
")",
";",
"}",
"while",
"(",
"(",
"$",
"last",
"=",
"end",
"(",
"$",
"sidebarActions",
")",
")",
"&&",
"$",
"last",
"[",
"'isSeparator'",
"]",
")",
"{",
"array_pop",
"(",
"$",
"sidebarActions",
")",
";",
"}",
"return",
"$",
"sidebarActions",
";",
"}"
]
| Parse the given actions as object actions.
@param array $actions Actions to resolve.
@return array | [
"Parse",
"the",
"given",
"actions",
"as",
"object",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L399-L454 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.defaultSidebarActions | protected function defaultSidebarActions()
{
if ($this->defaultSidebarActions === null) {
$this->defaultSidebarActions = [];
if ($this->form()) {
$save = [
'label' => $this->form()->submitLabel(),
'ident' => 'save',
'buttonType' => 'submit',
'priority' => 90
];
$this->defaultSidebarActions[] = $save;
}
}
return $this->defaultSidebarActions;
} | php | protected function defaultSidebarActions()
{
if ($this->defaultSidebarActions === null) {
$this->defaultSidebarActions = [];
if ($this->form()) {
$save = [
'label' => $this->form()->submitLabel(),
'ident' => 'save',
'buttonType' => 'submit',
'priority' => 90
];
$this->defaultSidebarActions[] = $save;
}
}
return $this->defaultSidebarActions;
} | [
"protected",
"function",
"defaultSidebarActions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"defaultSidebarActions",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultSidebarActions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"form",
"(",
")",
")",
"{",
"$",
"save",
"=",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"form",
"(",
")",
"->",
"submitLabel",
"(",
")",
",",
"'ident'",
"=>",
"'save'",
",",
"'buttonType'",
"=>",
"'submit'",
",",
"'priority'",
"=>",
"90",
"]",
";",
"$",
"this",
"->",
"defaultSidebarActions",
"[",
"]",
"=",
"$",
"save",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"defaultSidebarActions",
";",
"}"
]
| Retrieve the sidebar's default actions.
@return array | [
"Retrieve",
"the",
"sidebar",
"s",
"default",
"actions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L461-L478 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.isObjDeletable | public function isObjDeletable()
{
if ($this->isObjDeletable === null) {
// Overridden by permissions
if (!$this->checkPermission('delete') || !$this->form()) {
$this->isObjDeletable = false;
} else {
$obj = $this->form()->obj();
$this->isObjDeletable = !!$obj->id();
$method = [ $obj, 'isDeletable' ];
if (is_callable($method)) {
$this->isObjDeletable = call_user_func($method);
}
}
}
return $this->isObjDeletable;
} | php | public function isObjDeletable()
{
if ($this->isObjDeletable === null) {
// Overridden by permissions
if (!$this->checkPermission('delete') || !$this->form()) {
$this->isObjDeletable = false;
} else {
$obj = $this->form()->obj();
$this->isObjDeletable = !!$obj->id();
$method = [ $obj, 'isDeletable' ];
if (is_callable($method)) {
$this->isObjDeletable = call_user_func($method);
}
}
}
return $this->isObjDeletable;
} | [
"public",
"function",
"isObjDeletable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isObjDeletable",
"===",
"null",
")",
"{",
"// Overridden by permissions",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPermission",
"(",
"'delete'",
")",
"||",
"!",
"$",
"this",
"->",
"form",
"(",
")",
")",
"{",
"$",
"this",
"->",
"isObjDeletable",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"form",
"(",
")",
"->",
"obj",
"(",
")",
";",
"$",
"this",
"->",
"isObjDeletable",
"=",
"!",
"!",
"$",
"obj",
"->",
"id",
"(",
")",
";",
"$",
"method",
"=",
"[",
"$",
"obj",
",",
"'isDeletable'",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"isObjDeletable",
"=",
"call_user_func",
"(",
"$",
"method",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"isObjDeletable",
";",
"}"
]
| Determine if the object can be deleted.
If TRUE, the "Delete" button is shown. The object can still be
deleted programmatically or via direct action on the database.
@return boolean | [
"Determine",
"if",
"the",
"object",
"can",
"be",
"deleted",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L496-L514 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.isObjRevisionable | public function isObjRevisionable()
{
if ($this->isObjRevisionable === null) {
// Overridden by permissions
if (!$this->checkPermission('revision') || !$this->form()) {
$this->isObjRevisionable = false;
} else {
$obj = $this->form()->obj();
if (!$obj->id()) {
$this->isObjRevisionable = false;
return $this->isObjRevisionable;
}
if ($obj instanceof RevisionableInterface && $obj->revisionEnabled()) {
$this->isObjRevisionable = !!count($obj->allRevisions());
}
}
}
return $this->isObjRevisionable;
} | php | public function isObjRevisionable()
{
if ($this->isObjRevisionable === null) {
// Overridden by permissions
if (!$this->checkPermission('revision') || !$this->form()) {
$this->isObjRevisionable = false;
} else {
$obj = $this->form()->obj();
if (!$obj->id()) {
$this->isObjRevisionable = false;
return $this->isObjRevisionable;
}
if ($obj instanceof RevisionableInterface && $obj->revisionEnabled()) {
$this->isObjRevisionable = !!count($obj->allRevisions());
}
}
}
return $this->isObjRevisionable;
} | [
"public",
"function",
"isObjRevisionable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isObjRevisionable",
"===",
"null",
")",
"{",
"// Overridden by permissions",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPermission",
"(",
"'revision'",
")",
"||",
"!",
"$",
"this",
"->",
"form",
"(",
")",
")",
"{",
"$",
"this",
"->",
"isObjRevisionable",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"form",
"(",
")",
"->",
"obj",
"(",
")",
";",
"if",
"(",
"!",
"$",
"obj",
"->",
"id",
"(",
")",
")",
"{",
"$",
"this",
"->",
"isObjRevisionable",
"=",
"false",
";",
"return",
"$",
"this",
"->",
"isObjRevisionable",
";",
"}",
"if",
"(",
"$",
"obj",
"instanceof",
"RevisionableInterface",
"&&",
"$",
"obj",
"->",
"revisionEnabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"isObjRevisionable",
"=",
"!",
"!",
"count",
"(",
"$",
"obj",
"->",
"allRevisions",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"isObjRevisionable",
";",
"}"
]
| Determine if the object has revisions.
If TRUE, the "Delete" button is shown. The object can still be
deleted programmatically or via direct action on the database.
@return boolean | [
"Determine",
"if",
"the",
"object",
"has",
"revisions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L524-L544 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.isObjResettable | public function isObjResettable()
{
if ($this->isObjResettable === null) {
// Overridden by permissions
if (!$this->checkPermission('reset') || !$this->form()) {
$this->isObjResettable = false;
} else {
$this->isObjResettable = true;
$obj = $this->form()->obj();
$method = [ $obj, 'isResettable' ];
if (is_callable($method)) {
$this->isObjResettable = call_user_func($method);
}
}
}
return $this->isObjResettable;
} | php | public function isObjResettable()
{
if ($this->isObjResettable === null) {
// Overridden by permissions
if (!$this->checkPermission('reset') || !$this->form()) {
$this->isObjResettable = false;
} else {
$this->isObjResettable = true;
$obj = $this->form()->obj();
$method = [ $obj, 'isResettable' ];
if (is_callable($method)) {
$this->isObjResettable = call_user_func($method);
}
}
}
return $this->isObjResettable;
} | [
"public",
"function",
"isObjResettable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isObjResettable",
"===",
"null",
")",
"{",
"// Overridden by permissions",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPermission",
"(",
"'reset'",
")",
"||",
"!",
"$",
"this",
"->",
"form",
"(",
")",
")",
"{",
"$",
"this",
"->",
"isObjResettable",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"isObjResettable",
"=",
"true",
";",
"$",
"obj",
"=",
"$",
"this",
"->",
"form",
"(",
")",
"->",
"obj",
"(",
")",
";",
"$",
"method",
"=",
"[",
"$",
"obj",
",",
"'isResettable'",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"isObjResettable",
"=",
"call_user_func",
"(",
"$",
"method",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"isObjResettable",
";",
"}"
]
| Determine if the object can be reset.
If TRUE, the "Reset" button is shown. The object can still be
reset to its default values programmatically or emptied via direct
action on the database.
@return boolean | [
"Determine",
"if",
"the",
"object",
"can",
"be",
"reset",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L555-L573 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.isObjSavable | public function isObjSavable()
{
if ($this->isObjSavable === null) {
// Overridden by permissions
if (!$this->checkPermission('save') || !$this->form()) {
$this->isObjSavable = false;
} else {
$this->isObjSavable = true;
$obj = $this->form()->obj();
$method = [ $obj, 'isSavable' ];
if (is_callable($method)) {
$this->isObjSavable = call_user_func($method);
}
}
}
return $this->isObjSavable;
} | php | public function isObjSavable()
{
if ($this->isObjSavable === null) {
// Overridden by permissions
if (!$this->checkPermission('save') || !$this->form()) {
$this->isObjSavable = false;
} else {
$this->isObjSavable = true;
$obj = $this->form()->obj();
$method = [ $obj, 'isSavable' ];
if (is_callable($method)) {
$this->isObjSavable = call_user_func($method);
}
}
}
return $this->isObjSavable;
} | [
"public",
"function",
"isObjSavable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isObjSavable",
"===",
"null",
")",
"{",
"// Overridden by permissions",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPermission",
"(",
"'save'",
")",
"||",
"!",
"$",
"this",
"->",
"form",
"(",
")",
")",
"{",
"$",
"this",
"->",
"isObjSavable",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"isObjSavable",
"=",
"true",
";",
"$",
"obj",
"=",
"$",
"this",
"->",
"form",
"(",
")",
"->",
"obj",
"(",
")",
";",
"$",
"method",
"=",
"[",
"$",
"obj",
",",
"'isSavable'",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"isObjSavable",
"=",
"call_user_func",
"(",
"$",
"method",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"isObjSavable",
";",
"}"
]
| Determine if the object can be saved.
If TRUE, the "Save" button is shown. The object can still be
saved programmatically.
@return boolean | [
"Determine",
"if",
"the",
"object",
"can",
"be",
"saved",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L583-L601 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.showFooter | public function showFooter()
{
// Overridden by permissions
if (!$this->checkPermission('footer')) {
return false;
}
// Overridden by conditionals
if (!$this->isObjDeletable() && !$this->isObjResettable() &&!$this->isObjRevisionable()) {
return false;
}
return $this->showFooter;
} | php | public function showFooter()
{
// Overridden by permissions
if (!$this->checkPermission('footer')) {
return false;
}
// Overridden by conditionals
if (!$this->isObjDeletable() && !$this->isObjResettable() &&!$this->isObjRevisionable()) {
return false;
}
return $this->showFooter;
} | [
"public",
"function",
"showFooter",
"(",
")",
"{",
"// Overridden by permissions",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPermission",
"(",
"'footer'",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Overridden by conditionals",
"if",
"(",
"!",
"$",
"this",
"->",
"isObjDeletable",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isObjResettable",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isObjRevisionable",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"showFooter",
";",
"}"
]
| Determine if the sidebar's footer is visible.
@return boolean | [
"Determine",
"if",
"the",
"sidebar",
"s",
"footer",
"is",
"visible",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L727-L740 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormSidebarWidget.php | FormSidebarWidget.checkPermission | protected function checkPermission($permissionName)
{
if (isset($this->requiredGlobalAclPermissions[$permissionName])) {
$permissions = $this->requiredGlobalAclPermissions[$permissionName];
} elseif (isset($this->requiredAclPermissions()[$permissionName])) {
$permissions = $this->requiredAclPermissions()[$permissionName];
} else {
return true;
}
// Test sidebar vs. ACL roles
$authUser = $this->authenticator()->authenticate();
if (!$this->authorizer()->userAllowed($authUser, $permissions)) {
header('HTTP/1.0 403 Forbidden');
header('Location: '.$this->adminUrl().'login');
return false;
}
return true;
} | php | protected function checkPermission($permissionName)
{
if (isset($this->requiredGlobalAclPermissions[$permissionName])) {
$permissions = $this->requiredGlobalAclPermissions[$permissionName];
} elseif (isset($this->requiredAclPermissions()[$permissionName])) {
$permissions = $this->requiredAclPermissions()[$permissionName];
} else {
return true;
}
// Test sidebar vs. ACL roles
$authUser = $this->authenticator()->authenticate();
if (!$this->authorizer()->userAllowed($authUser, $permissions)) {
header('HTTP/1.0 403 Forbidden');
header('Location: '.$this->adminUrl().'login');
return false;
}
return true;
} | [
"protected",
"function",
"checkPermission",
"(",
"$",
"permissionName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"requiredGlobalAclPermissions",
"[",
"$",
"permissionName",
"]",
")",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"requiredGlobalAclPermissions",
"[",
"$",
"permissionName",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"requiredAclPermissions",
"(",
")",
"[",
"$",
"permissionName",
"]",
")",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"requiredAclPermissions",
"(",
")",
"[",
"$",
"permissionName",
"]",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"// Test sidebar vs. ACL roles",
"$",
"authUser",
"=",
"$",
"this",
"->",
"authenticator",
"(",
")",
"->",
"authenticate",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorizer",
"(",
")",
"->",
"userAllowed",
"(",
"$",
"authUser",
",",
"$",
"permissions",
")",
")",
"{",
"header",
"(",
"'HTTP/1.0 403 Forbidden'",
")",
";",
"header",
"(",
"'Location: '",
".",
"$",
"this",
"->",
"adminUrl",
"(",
")",
".",
"'login'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Return true if the user as required permissions.
@param string $permissionName The permission name to check against the user's permissions.
@return boolean | [
"Return",
"true",
"if",
"the",
"user",
"as",
"required",
"permissions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormSidebarWidget.php#L891-L911 | train |
acquia/commerce-manager | modules/acm/src/Element/AcmAddress.php | AcmAddress.calculateDynamicParts | public static function calculateDynamicParts($country) {
$dynamic_parts = [];
$addressFormatRepository = \Drupal::service('address.address_format_repository');
$address_format = $addressFormatRepository->get($country);
$subdivisionRepository = \Drupal::service('address.subdivision_repository');
$options = $subdivisionRepository->getList([$country]);
$labels = LabelHelper::getFieldLabels($address_format);
// Update region options based on country.
$dynamic_parts['region']['#options'] = $options;
$dynamic_parts['region']['#required'] = TRUE;
$dynamic_parts['region']['#access'] = TRUE;
// Update labels.
$cityLabel = $labels['locality'];
$postcodeLabel = $labels['postalCode'];
$regionLabel = $labels['administrativeArea'];
$dynamic_parts['region']['#title'] = $regionLabel;
$dynamic_parts['postcode']['#title'] = $postcodeLabel;
$dynamic_parts['city']['#title'] = $cityLabel;
if (empty($cityLabel)) {
$dynamic_parts['city']['#required'] = FALSE;
$dynamic_parts['city']['#access'] = FALSE;
}
if (empty($postcodeLabel)) {
$dynamic_parts['postcode']['#required'] = FALSE;
$dynamic_parts['postcode']['#access'] = FALSE;
}
if (empty($regionLabel) || empty($options)) {
$dynamic_parts['region']['#required'] = FALSE;
$dynamic_parts['region']['#access'] = FALSE;
}
return $dynamic_parts;
} | php | public static function calculateDynamicParts($country) {
$dynamic_parts = [];
$addressFormatRepository = \Drupal::service('address.address_format_repository');
$address_format = $addressFormatRepository->get($country);
$subdivisionRepository = \Drupal::service('address.subdivision_repository');
$options = $subdivisionRepository->getList([$country]);
$labels = LabelHelper::getFieldLabels($address_format);
// Update region options based on country.
$dynamic_parts['region']['#options'] = $options;
$dynamic_parts['region']['#required'] = TRUE;
$dynamic_parts['region']['#access'] = TRUE;
// Update labels.
$cityLabel = $labels['locality'];
$postcodeLabel = $labels['postalCode'];
$regionLabel = $labels['administrativeArea'];
$dynamic_parts['region']['#title'] = $regionLabel;
$dynamic_parts['postcode']['#title'] = $postcodeLabel;
$dynamic_parts['city']['#title'] = $cityLabel;
if (empty($cityLabel)) {
$dynamic_parts['city']['#required'] = FALSE;
$dynamic_parts['city']['#access'] = FALSE;
}
if (empty($postcodeLabel)) {
$dynamic_parts['postcode']['#required'] = FALSE;
$dynamic_parts['postcode']['#access'] = FALSE;
}
if (empty($regionLabel) || empty($options)) {
$dynamic_parts['region']['#required'] = FALSE;
$dynamic_parts['region']['#access'] = FALSE;
}
return $dynamic_parts;
} | [
"public",
"static",
"function",
"calculateDynamicParts",
"(",
"$",
"country",
")",
"{",
"$",
"dynamic_parts",
"=",
"[",
"]",
";",
"$",
"addressFormatRepository",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'address.address_format_repository'",
")",
";",
"$",
"address_format",
"=",
"$",
"addressFormatRepository",
"->",
"get",
"(",
"$",
"country",
")",
";",
"$",
"subdivisionRepository",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'address.subdivision_repository'",
")",
";",
"$",
"options",
"=",
"$",
"subdivisionRepository",
"->",
"getList",
"(",
"[",
"$",
"country",
"]",
")",
";",
"$",
"labels",
"=",
"LabelHelper",
"::",
"getFieldLabels",
"(",
"$",
"address_format",
")",
";",
"// Update region options based on country.",
"$",
"dynamic_parts",
"[",
"'region'",
"]",
"[",
"'#options'",
"]",
"=",
"$",
"options",
";",
"$",
"dynamic_parts",
"[",
"'region'",
"]",
"[",
"'#required'",
"]",
"=",
"TRUE",
";",
"$",
"dynamic_parts",
"[",
"'region'",
"]",
"[",
"'#access'",
"]",
"=",
"TRUE",
";",
"// Update labels.",
"$",
"cityLabel",
"=",
"$",
"labels",
"[",
"'locality'",
"]",
";",
"$",
"postcodeLabel",
"=",
"$",
"labels",
"[",
"'postalCode'",
"]",
";",
"$",
"regionLabel",
"=",
"$",
"labels",
"[",
"'administrativeArea'",
"]",
";",
"$",
"dynamic_parts",
"[",
"'region'",
"]",
"[",
"'#title'",
"]",
"=",
"$",
"regionLabel",
";",
"$",
"dynamic_parts",
"[",
"'postcode'",
"]",
"[",
"'#title'",
"]",
"=",
"$",
"postcodeLabel",
";",
"$",
"dynamic_parts",
"[",
"'city'",
"]",
"[",
"'#title'",
"]",
"=",
"$",
"cityLabel",
";",
"if",
"(",
"empty",
"(",
"$",
"cityLabel",
")",
")",
"{",
"$",
"dynamic_parts",
"[",
"'city'",
"]",
"[",
"'#required'",
"]",
"=",
"FALSE",
";",
"$",
"dynamic_parts",
"[",
"'city'",
"]",
"[",
"'#access'",
"]",
"=",
"FALSE",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"postcodeLabel",
")",
")",
"{",
"$",
"dynamic_parts",
"[",
"'postcode'",
"]",
"[",
"'#required'",
"]",
"=",
"FALSE",
";",
"$",
"dynamic_parts",
"[",
"'postcode'",
"]",
"[",
"'#access'",
"]",
"=",
"FALSE",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"regionLabel",
")",
"||",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"$",
"dynamic_parts",
"[",
"'region'",
"]",
"[",
"'#required'",
"]",
"=",
"FALSE",
";",
"$",
"dynamic_parts",
"[",
"'region'",
"]",
"[",
"'#access'",
"]",
"=",
"FALSE",
";",
"}",
"return",
"$",
"dynamic_parts",
";",
"}"
]
| Calculate dynamic address parts per country.
@param string $country
Country code.
@return array
Calculated dynamic form parts. | [
"Calculate",
"dynamic",
"address",
"parts",
"per",
"country",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Element/AcmAddress.php#L52-L89 | train |
acquia/commerce-manager | modules/acm/src/Element/AcmAddress.php | AcmAddress.validateAddress | public static function validateAddress(&$element, FormStateInterface $form_state, &$complete_form) {
$address = $element['#value'];
$address_review_text = $element['#address_review_text'];
$address_failed_text = $element['#address_failed_text'];
// Make sure these fields have values before trying to validate the address.
$required_fields = [
'street',
'city',
'region',
'postcode',
];
$skip = FALSE;
foreach ($required_fields as $required_field) {
if (empty($address[$required_field])) {
$skip = TRUE;
break;
}
}
// Skip validation if not all fields are filled out yet.
if ($skip) {
return $element;
}
try {
$response = \Drupal::service('acm.api')
->validateCustomerAddress($address);
// Address is valid and no suggestion came back.
if (isset($response['result']['valid']) && empty($response['result']['suggested'])) {
drupal_set_message($address_review_text, 'status');
}
// Address is in review and there's a suggestion that we use to pre-fill
// the address fields.
elseif (isset($response['result']['suggested']) && !empty($response['result']['suggested'])) {
$suggested_address = reset($response['result']['suggested']);
foreach ($suggested_address as $field => $value) {
if (!empty($value)) {
if (isset($element[$field])) {
$form_state->setValueForElement($element[$field], $value);
}
elseif (isset($element['dynamic_parts'][$field])) {
$form_state->setValueForElement($element['dynamic_parts'][$field], $value);
}
}
}
drupal_set_message($address_review_text, 'status');
}
// Address failed validation.
else {
$form_state->setError($element, $address_failed_text);
}
}
catch (RouteException $e) {
$form_state->setError($element, $address_failed_text);
}
return $element;
} | php | public static function validateAddress(&$element, FormStateInterface $form_state, &$complete_form) {
$address = $element['#value'];
$address_review_text = $element['#address_review_text'];
$address_failed_text = $element['#address_failed_text'];
// Make sure these fields have values before trying to validate the address.
$required_fields = [
'street',
'city',
'region',
'postcode',
];
$skip = FALSE;
foreach ($required_fields as $required_field) {
if (empty($address[$required_field])) {
$skip = TRUE;
break;
}
}
// Skip validation if not all fields are filled out yet.
if ($skip) {
return $element;
}
try {
$response = \Drupal::service('acm.api')
->validateCustomerAddress($address);
// Address is valid and no suggestion came back.
if (isset($response['result']['valid']) && empty($response['result']['suggested'])) {
drupal_set_message($address_review_text, 'status');
}
// Address is in review and there's a suggestion that we use to pre-fill
// the address fields.
elseif (isset($response['result']['suggested']) && !empty($response['result']['suggested'])) {
$suggested_address = reset($response['result']['suggested']);
foreach ($suggested_address as $field => $value) {
if (!empty($value)) {
if (isset($element[$field])) {
$form_state->setValueForElement($element[$field], $value);
}
elseif (isset($element['dynamic_parts'][$field])) {
$form_state->setValueForElement($element['dynamic_parts'][$field], $value);
}
}
}
drupal_set_message($address_review_text, 'status');
}
// Address failed validation.
else {
$form_state->setError($element, $address_failed_text);
}
}
catch (RouteException $e) {
$form_state->setError($element, $address_failed_text);
}
return $element;
} | [
"public",
"static",
"function",
"validateAddress",
"(",
"&",
"$",
"element",
",",
"FormStateInterface",
"$",
"form_state",
",",
"&",
"$",
"complete_form",
")",
"{",
"$",
"address",
"=",
"$",
"element",
"[",
"'#value'",
"]",
";",
"$",
"address_review_text",
"=",
"$",
"element",
"[",
"'#address_review_text'",
"]",
";",
"$",
"address_failed_text",
"=",
"$",
"element",
"[",
"'#address_failed_text'",
"]",
";",
"// Make sure these fields have values before trying to validate the address.",
"$",
"required_fields",
"=",
"[",
"'street'",
",",
"'city'",
",",
"'region'",
",",
"'postcode'",
",",
"]",
";",
"$",
"skip",
"=",
"FALSE",
";",
"foreach",
"(",
"$",
"required_fields",
"as",
"$",
"required_field",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"address",
"[",
"$",
"required_field",
"]",
")",
")",
"{",
"$",
"skip",
"=",
"TRUE",
";",
"break",
";",
"}",
"}",
"// Skip validation if not all fields are filled out yet.",
"if",
"(",
"$",
"skip",
")",
"{",
"return",
"$",
"element",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm.api'",
")",
"->",
"validateCustomerAddress",
"(",
"$",
"address",
")",
";",
"// Address is valid and no suggestion came back.",
"if",
"(",
"isset",
"(",
"$",
"response",
"[",
"'result'",
"]",
"[",
"'valid'",
"]",
")",
"&&",
"empty",
"(",
"$",
"response",
"[",
"'result'",
"]",
"[",
"'suggested'",
"]",
")",
")",
"{",
"drupal_set_message",
"(",
"$",
"address_review_text",
",",
"'status'",
")",
";",
"}",
"// Address is in review and there's a suggestion that we use to pre-fill",
"// the address fields.",
"elseif",
"(",
"isset",
"(",
"$",
"response",
"[",
"'result'",
"]",
"[",
"'suggested'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"response",
"[",
"'result'",
"]",
"[",
"'suggested'",
"]",
")",
")",
"{",
"$",
"suggested_address",
"=",
"reset",
"(",
"$",
"response",
"[",
"'result'",
"]",
"[",
"'suggested'",
"]",
")",
";",
"foreach",
"(",
"$",
"suggested_address",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"element",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"form_state",
"->",
"setValueForElement",
"(",
"$",
"element",
"[",
"$",
"field",
"]",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"element",
"[",
"'dynamic_parts'",
"]",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"form_state",
"->",
"setValueForElement",
"(",
"$",
"element",
"[",
"'dynamic_parts'",
"]",
"[",
"$",
"field",
"]",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"drupal_set_message",
"(",
"$",
"address_review_text",
",",
"'status'",
")",
";",
"}",
"// Address failed validation.",
"else",
"{",
"$",
"form_state",
"->",
"setError",
"(",
"$",
"element",
",",
"$",
"address_failed_text",
")",
";",
"}",
"}",
"catch",
"(",
"RouteException",
"$",
"e",
")",
"{",
"$",
"form_state",
"->",
"setError",
"(",
"$",
"element",
",",
"$",
"address_failed_text",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
]
| Validates an acm_address element. | [
"Validates",
"an",
"acm_address",
"element",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Element/AcmAddress.php#L327-L389 | train |
acquia/commerce-manager | modules/acm/src/Element/AcmAddress.php | AcmAddress.addressAjaxCallback | public static function addressAjaxCallback(array $form, FormStateInterface $form_state, Request $request) {
$form_parents = explode('/', $request->query->get('element_parents'));
// Retrieve the element to be rendered.
$form = NestedArray::getValue($form, $form_parents);
$values = $form_state->getValue($form['#parents']);
$country = $values['country_id'];
$dynamic_parts = self::calculateDynamicParts($country);
return array_replace_recursive($form['dynamic_parts'], $dynamic_parts);
} | php | public static function addressAjaxCallback(array $form, FormStateInterface $form_state, Request $request) {
$form_parents = explode('/', $request->query->get('element_parents'));
// Retrieve the element to be rendered.
$form = NestedArray::getValue($form, $form_parents);
$values = $form_state->getValue($form['#parents']);
$country = $values['country_id'];
$dynamic_parts = self::calculateDynamicParts($country);
return array_replace_recursive($form['dynamic_parts'], $dynamic_parts);
} | [
"public",
"static",
"function",
"addressAjaxCallback",
"(",
"array",
"$",
"form",
",",
"FormStateInterface",
"$",
"form_state",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"form_parents",
"=",
"explode",
"(",
"'/'",
",",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'element_parents'",
")",
")",
";",
"// Retrieve the element to be rendered.",
"$",
"form",
"=",
"NestedArray",
"::",
"getValue",
"(",
"$",
"form",
",",
"$",
"form_parents",
")",
";",
"$",
"values",
"=",
"$",
"form_state",
"->",
"getValue",
"(",
"$",
"form",
"[",
"'#parents'",
"]",
")",
";",
"$",
"country",
"=",
"$",
"values",
"[",
"'country_id'",
"]",
";",
"$",
"dynamic_parts",
"=",
"self",
"::",
"calculateDynamicParts",
"(",
"$",
"country",
")",
";",
"return",
"array_replace_recursive",
"(",
"$",
"form",
"[",
"'dynamic_parts'",
"]",
",",
"$",
"dynamic_parts",
")",
";",
"}"
]
| Ajax handler for country selector.
@param array $form
The build form.
@param \Drupal\Core\Form\FormStateInterface $form_state
The form state.
@param \Symfony\Component\HttpFoundation\Request $request
The current request.
@return \Drupal\Core\Ajax\AjaxResponse
The ajax response of the ajax upload. | [
"Ajax",
"handler",
"for",
"country",
"selector",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Element/AcmAddress.php#L404-L415 | train |
acquia/commerce-manager | modules/acm_customer/src/Plugin/CustomerPages/CustomerPagesBase.php | CustomerPagesBase.processPageId | protected function processPageId($page_id) {
$page_ids = array_keys($this->getVisiblePages());
// Redirect to default page (first page) if no page or invalid page is
// requested.
if (empty($page_id) || !in_array($page_id, $page_ids)) {
$page_id = reset($page_ids);
}
return $page_id;
} | php | protected function processPageId($page_id) {
$page_ids = array_keys($this->getVisiblePages());
// Redirect to default page (first page) if no page or invalid page is
// requested.
if (empty($page_id) || !in_array($page_id, $page_ids)) {
$page_id = reset($page_ids);
}
return $page_id;
} | [
"protected",
"function",
"processPageId",
"(",
"$",
"page_id",
")",
"{",
"$",
"page_ids",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"getVisiblePages",
"(",
")",
")",
";",
"// Redirect to default page (first page) if no page or invalid page is",
"// requested.",
"if",
"(",
"empty",
"(",
"$",
"page_id",
")",
"||",
"!",
"in_array",
"(",
"$",
"page_id",
",",
"$",
"page_ids",
")",
")",
"{",
"$",
"page_id",
"=",
"reset",
"(",
"$",
"page_ids",
")",
";",
"}",
"return",
"$",
"page_id",
";",
"}"
]
| Processes the requested page ID.
@param string $page_id
The page ID.
@return string
The processed page ID. | [
"Processes",
"the",
"requested",
"page",
"ID",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Plugin/CustomerPages/CustomerPagesBase.php#L140-L150 | train |
acquia/commerce-manager | modules/acm_customer/src/Plugin/CustomerPages/CustomerPagesBase.php | CustomerPagesBase.getFormConfiguration | protected function getFormConfiguration($form_id) {
$form_configuration = [];
if (isset($this->configuration['child_forms'][$form_id])) {
$form_configuration = $this->configuration['child_forms'][$form_id];
}
return $form_configuration;
} | php | protected function getFormConfiguration($form_id) {
$form_configuration = [];
if (isset($this->configuration['child_forms'][$form_id])) {
$form_configuration = $this->configuration['child_forms'][$form_id];
}
return $form_configuration;
} | [
"protected",
"function",
"getFormConfiguration",
"(",
"$",
"form_id",
")",
"{",
"$",
"form_configuration",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'child_forms'",
"]",
"[",
"$",
"form_id",
"]",
")",
")",
"{",
"$",
"form_configuration",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'child_forms'",
"]",
"[",
"$",
"form_id",
"]",
";",
"}",
"return",
"$",
"form_configuration",
";",
"}"
]
| Gets the configuration for the given form.
@param string $form_id
The form ID.
@return array
The form configuration. | [
"Gets",
"the",
"configuration",
"for",
"the",
"given",
"form",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Plugin/CustomerPages/CustomerPagesBase.php#L310-L318 | train |
acquia/commerce-manager | modules/acm_customer/src/Commands/AcmCustomerDrushCommands.php | AcmCustomerDrushCommands.pushCustomersData | public function pushCustomersData() {
$query = $this->connection->select('users_field_data', 'user');
$query->addField('user', 'mail');
$query->condition('status', 0, '>');
$query->condition('acm_customer_id', 0, '>');
$result = $query->countQuery()->execute()->fetchAssoc();
if ($result['expression'] == 0) {
$this->logger->warning('No customers with active status available to push.');
return;
}
$question = dt('There are @count customers as of now, are you sure you want to push for all?', [
'@count' => $result['expression'],
]);
if (!$this->confirm($question)) {
throw new UserAbortException();
}
$query = $this->connection->select('users_field_data', 'user');
$query->addField('user', 'mail');
$query->condition('status', 0, '>');
$query->condition('acm_customer_id', 0, '>');
$result = $query->execute()->fetchAll(\PDO::FETCH_ASSOC);
$customers = array_column($result, 'mail');
$batch = [
'title' => 'Push Customers Data',
'init_message' => 'Pushing customers data...',
'error_message' => 'Error occurred while pushing customers, please check logs.',
];
foreach (array_chunk($customers, self::BATCH_SIZE) as $customers_batch) {
$batch['operations'][] = [
[__CLASS__, 'pushCustomerDataInBatch'],
[$customers_batch],
];
}
batch_set($batch);
drush_backend_batch_process();
$this->logger()->info('Finished pushing customers data, please check logs for more details.');
} | php | public function pushCustomersData() {
$query = $this->connection->select('users_field_data', 'user');
$query->addField('user', 'mail');
$query->condition('status', 0, '>');
$query->condition('acm_customer_id', 0, '>');
$result = $query->countQuery()->execute()->fetchAssoc();
if ($result['expression'] == 0) {
$this->logger->warning('No customers with active status available to push.');
return;
}
$question = dt('There are @count customers as of now, are you sure you want to push for all?', [
'@count' => $result['expression'],
]);
if (!$this->confirm($question)) {
throw new UserAbortException();
}
$query = $this->connection->select('users_field_data', 'user');
$query->addField('user', 'mail');
$query->condition('status', 0, '>');
$query->condition('acm_customer_id', 0, '>');
$result = $query->execute()->fetchAll(\PDO::FETCH_ASSOC);
$customers = array_column($result, 'mail');
$batch = [
'title' => 'Push Customers Data',
'init_message' => 'Pushing customers data...',
'error_message' => 'Error occurred while pushing customers, please check logs.',
];
foreach (array_chunk($customers, self::BATCH_SIZE) as $customers_batch) {
$batch['operations'][] = [
[__CLASS__, 'pushCustomerDataInBatch'],
[$customers_batch],
];
}
batch_set($batch);
drush_backend_batch_process();
$this->logger()->info('Finished pushing customers data, please check logs for more details.');
} | [
"public",
"function",
"pushCustomersData",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"select",
"(",
"'users_field_data'",
",",
"'user'",
")",
";",
"$",
"query",
"->",
"addField",
"(",
"'user'",
",",
"'mail'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'status'",
",",
"0",
",",
"'>'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'acm_customer_id'",
",",
"0",
",",
"'>'",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"countQuery",
"(",
")",
"->",
"execute",
"(",
")",
"->",
"fetchAssoc",
"(",
")",
";",
"if",
"(",
"$",
"result",
"[",
"'expression'",
"]",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"'No customers with active status available to push.'",
")",
";",
"return",
";",
"}",
"$",
"question",
"=",
"dt",
"(",
"'There are @count customers as of now, are you sure you want to push for all?'",
",",
"[",
"'@count'",
"=>",
"$",
"result",
"[",
"'expression'",
"]",
",",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"confirm",
"(",
"$",
"question",
")",
")",
"{",
"throw",
"new",
"UserAbortException",
"(",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"select",
"(",
"'users_field_data'",
",",
"'user'",
")",
";",
"$",
"query",
"->",
"addField",
"(",
"'user'",
",",
"'mail'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'status'",
",",
"0",
",",
"'>'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'acm_customer_id'",
",",
"0",
",",
"'>'",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"customers",
"=",
"array_column",
"(",
"$",
"result",
",",
"'mail'",
")",
";",
"$",
"batch",
"=",
"[",
"'title'",
"=>",
"'Push Customers Data'",
",",
"'init_message'",
"=>",
"'Pushing customers data...'",
",",
"'error_message'",
"=>",
"'Error occurred while pushing customers, please check logs.'",
",",
"]",
";",
"foreach",
"(",
"array_chunk",
"(",
"$",
"customers",
",",
"self",
"::",
"BATCH_SIZE",
")",
"as",
"$",
"customers_batch",
")",
"{",
"$",
"batch",
"[",
"'operations'",
"]",
"[",
"]",
"=",
"[",
"[",
"__CLASS__",
",",
"'pushCustomerDataInBatch'",
"]",
",",
"[",
"$",
"customers_batch",
"]",
",",
"]",
";",
"}",
"batch_set",
"(",
"$",
"batch",
")",
";",
"drush_backend_batch_process",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"(",
")",
"->",
"info",
"(",
"'Finished pushing customers data, please check logs for more details.'",
")",
";",
"}"
]
| Push all the customers available in Drupal to upstream system.
@command acm_customer:push-customers
@validate-module-enabled acm_customer
@aliases push-customers
@usage drush push-customers
Push all the customers available in Drupal to upstream system. | [
"Push",
"all",
"the",
"customers",
"available",
"in",
"Drupal",
"to",
"upstream",
"system",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Commands/AcmCustomerDrushCommands.php#L52-L97 | train |
acquia/commerce-manager | modules/acm_customer/src/Commands/AcmCustomerDrushCommands.php | AcmCustomerDrushCommands.pushCustomerData | public function pushCustomerData(string $mail) {
self::pushCustomerDataToUpstream($mail);
$this->logger()->info('Pushed customer data for @mail, please check logs for more details.', [
'@mail' => $mail,
]);
} | php | public function pushCustomerData(string $mail) {
self::pushCustomerDataToUpstream($mail);
$this->logger()->info('Pushed customer data for @mail, please check logs for more details.', [
'@mail' => $mail,
]);
} | [
"public",
"function",
"pushCustomerData",
"(",
"string",
"$",
"mail",
")",
"{",
"self",
"::",
"pushCustomerDataToUpstream",
"(",
"$",
"mail",
")",
";",
"$",
"this",
"->",
"logger",
"(",
")",
"->",
"info",
"(",
"'Pushed customer data for @mail, please check logs for more details.'",
",",
"[",
"'@mail'",
"=>",
"$",
"mail",
",",
"]",
")",
";",
"}"
]
| Push specific customer available in Drupal to upstream system.
@param string $mail
E-Mail address of the customer to push.
@command acm_customer:push-customer
@validate-module-enabled acm_customer
@aliases push-customer
@usage drush push-customer [email protected]
Push specific customer available in Drupal to upstream system. | [
"Push",
"specific",
"customer",
"available",
"in",
"Drupal",
"to",
"upstream",
"system",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Commands/AcmCustomerDrushCommands.php#L114-L119 | train |
acquia/commerce-manager | modules/acm_customer/src/Commands/AcmCustomerDrushCommands.php | AcmCustomerDrushCommands.pushCustomerDataToUpstream | public static function pushCustomerDataToUpstream(string $mail) {
$logger = \Drupal::logger('AcmCustomerDrushCommands');
/** @var \Drupal\user\Entity\User $user */
$user = user_load_by_mail($mail);
if (empty($user)) {
$logger->warning('User with @mail not found, skipping.', [
'@mail' => $mail,
]);
}
elseif (empty($user->get('acm_customer_id')->getString())) {
$logger->warning('User with @mail does not have customer id, skipping.', [
'@mail' => $mail,
]);
}
$customer_array = [
'customer_id' => $user->get('acm_customer_id')->getString(),
'firstname' => $user->get('field_first_name')->getString(),
'lastname' => $user->get('field_last_name')->getString(),
'email' => $user->getEmail(),
];
/** @var \Drupal\acm\Connector\APIWrapper $api_wrapper */
$api_wrapper = \Drupal::service('acm.api');
try {
if ($api_wrapper->updateCustomer($customer_array)) {
$logger->info('Successfully pushed for user with @mail.', [
'@mail' => $mail,
]);
}
else {
$logger->warning('Something went wrong while pushing user with @mail.', [
'@mail' => $mail,
]);
}
}
catch (\Exception $e) {
$logger->error('Failed to push for user with @mail, message: @message.', [
'@mail' => $mail,
'@message' => $e->getMessage(),
]);
}
} | php | public static function pushCustomerDataToUpstream(string $mail) {
$logger = \Drupal::logger('AcmCustomerDrushCommands');
/** @var \Drupal\user\Entity\User $user */
$user = user_load_by_mail($mail);
if (empty($user)) {
$logger->warning('User with @mail not found, skipping.', [
'@mail' => $mail,
]);
}
elseif (empty($user->get('acm_customer_id')->getString())) {
$logger->warning('User with @mail does not have customer id, skipping.', [
'@mail' => $mail,
]);
}
$customer_array = [
'customer_id' => $user->get('acm_customer_id')->getString(),
'firstname' => $user->get('field_first_name')->getString(),
'lastname' => $user->get('field_last_name')->getString(),
'email' => $user->getEmail(),
];
/** @var \Drupal\acm\Connector\APIWrapper $api_wrapper */
$api_wrapper = \Drupal::service('acm.api');
try {
if ($api_wrapper->updateCustomer($customer_array)) {
$logger->info('Successfully pushed for user with @mail.', [
'@mail' => $mail,
]);
}
else {
$logger->warning('Something went wrong while pushing user with @mail.', [
'@mail' => $mail,
]);
}
}
catch (\Exception $e) {
$logger->error('Failed to push for user with @mail, message: @message.', [
'@mail' => $mail,
'@message' => $e->getMessage(),
]);
}
} | [
"public",
"static",
"function",
"pushCustomerDataToUpstream",
"(",
"string",
"$",
"mail",
")",
"{",
"$",
"logger",
"=",
"\\",
"Drupal",
"::",
"logger",
"(",
"'AcmCustomerDrushCommands'",
")",
";",
"/** @var \\Drupal\\user\\Entity\\User $user */",
"$",
"user",
"=",
"user_load_by_mail",
"(",
"$",
"mail",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"$",
"logger",
"->",
"warning",
"(",
"'User with @mail not found, skipping.'",
",",
"[",
"'@mail'",
"=>",
"$",
"mail",
",",
"]",
")",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"user",
"->",
"get",
"(",
"'acm_customer_id'",
")",
"->",
"getString",
"(",
")",
")",
")",
"{",
"$",
"logger",
"->",
"warning",
"(",
"'User with @mail does not have customer id, skipping.'",
",",
"[",
"'@mail'",
"=>",
"$",
"mail",
",",
"]",
")",
";",
"}",
"$",
"customer_array",
"=",
"[",
"'customer_id'",
"=>",
"$",
"user",
"->",
"get",
"(",
"'acm_customer_id'",
")",
"->",
"getString",
"(",
")",
",",
"'firstname'",
"=>",
"$",
"user",
"->",
"get",
"(",
"'field_first_name'",
")",
"->",
"getString",
"(",
")",
",",
"'lastname'",
"=>",
"$",
"user",
"->",
"get",
"(",
"'field_last_name'",
")",
"->",
"getString",
"(",
")",
",",
"'email'",
"=>",
"$",
"user",
"->",
"getEmail",
"(",
")",
",",
"]",
";",
"/** @var \\Drupal\\acm\\Connector\\APIWrapper $api_wrapper */",
"$",
"api_wrapper",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm.api'",
")",
";",
"try",
"{",
"if",
"(",
"$",
"api_wrapper",
"->",
"updateCustomer",
"(",
"$",
"customer_array",
")",
")",
"{",
"$",
"logger",
"->",
"info",
"(",
"'Successfully pushed for user with @mail.'",
",",
"[",
"'@mail'",
"=>",
"$",
"mail",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"logger",
"->",
"warning",
"(",
"'Something went wrong while pushing user with @mail.'",
",",
"[",
"'@mail'",
"=>",
"$",
"mail",
",",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"logger",
"->",
"error",
"(",
"'Failed to push for user with @mail, message: @message.'",
",",
"[",
"'@mail'",
"=>",
"$",
"mail",
",",
"'@message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"]",
")",
";",
"}",
"}"
]
| Wrapper function to push data for particular customer.
@param string $mail
E-Mail address of the customer to push. | [
"Wrapper",
"function",
"to",
"push",
"data",
"for",
"particular",
"customer",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Commands/AcmCustomerDrushCommands.php#L141-L186 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormGroup/TemplateOptionsFormGroup.php | TemplateOptionsFormGroup.setTemplateProperty | public function setTemplateProperty($propertyIdent)
{
if ($propertyIdent === null) {
$this->templateProperty = null;
return $this;
}
$property = null;
if ($propertyIdent instanceof PropertyInterface) {
$property = $propertyIdent;
$propertyIdent = $property->ident();
} elseif (!is_string($propertyIdent)) {
throw new InvalidArgumentException(
'Property identifier must be a string'
);
}
$obj = $this->obj();
if (!$obj->hasProperty($propertyIdent)) {
throw new UnexpectedValueException(sprintf(
'The "%1$s" property is not defined on [%2$s]',
$propertyIdent,
get_class($this->obj())
));
}
if ($property === null) {
$property = $obj->property($propertyIdent);
}
$this->templateProperty = $property;
return $this;
} | php | public function setTemplateProperty($propertyIdent)
{
if ($propertyIdent === null) {
$this->templateProperty = null;
return $this;
}
$property = null;
if ($propertyIdent instanceof PropertyInterface) {
$property = $propertyIdent;
$propertyIdent = $property->ident();
} elseif (!is_string($propertyIdent)) {
throw new InvalidArgumentException(
'Property identifier must be a string'
);
}
$obj = $this->obj();
if (!$obj->hasProperty($propertyIdent)) {
throw new UnexpectedValueException(sprintf(
'The "%1$s" property is not defined on [%2$s]',
$propertyIdent,
get_class($this->obj())
));
}
if ($property === null) {
$property = $obj->property($propertyIdent);
}
$this->templateProperty = $property;
return $this;
} | [
"public",
"function",
"setTemplateProperty",
"(",
"$",
"propertyIdent",
")",
"{",
"if",
"(",
"$",
"propertyIdent",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"templateProperty",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"$",
"property",
"=",
"null",
";",
"if",
"(",
"$",
"propertyIdent",
"instanceof",
"PropertyInterface",
")",
"{",
"$",
"property",
"=",
"$",
"propertyIdent",
";",
"$",
"propertyIdent",
"=",
"$",
"property",
"->",
"ident",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"is_string",
"(",
"$",
"propertyIdent",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Property identifier must be a string'",
")",
";",
"}",
"$",
"obj",
"=",
"$",
"this",
"->",
"obj",
"(",
")",
";",
"if",
"(",
"!",
"$",
"obj",
"->",
"hasProperty",
"(",
"$",
"propertyIdent",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'The \"%1$s\" property is not defined on [%2$s]'",
",",
"$",
"propertyIdent",
",",
"get_class",
"(",
"$",
"this",
"->",
"obj",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"property",
"===",
"null",
")",
"{",
"$",
"property",
"=",
"$",
"obj",
"->",
"property",
"(",
"$",
"propertyIdent",
")",
";",
"}",
"$",
"this",
"->",
"templateProperty",
"=",
"$",
"property",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the form object's property for template controller choices.
Must be a property of the form's object model that will supply a list of properties.
@param string|PropertyInterface $propertyIdent The property identifier—or instance—of a storage property.
@throws InvalidArgumentException If the property identifier is not a string.
@throws UnexpectedValueException If a property data is invalid.
@return StructureFormGroup | [
"Set",
"the",
"form",
"object",
"s",
"property",
"for",
"template",
"controller",
"choices",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/TemplateOptionsFormGroup.php#L156-L190 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormGroup/TemplateOptionsFormGroup.php | TemplateOptionsFormGroup.templateProperty | public function templateProperty()
{
if ($this->templateProperty === null) {
$obj = $this->obj();
if ($obj instanceof TemplateableInterface) {
$this->setTemplateProperty($obj->property('template_ident'));
} else {
throw new RuntimeException(sprintf(
'Storage property owner is not defined for "%s"',
get_class($this)
));
}
}
return $this->templateProperty;
} | php | public function templateProperty()
{
if ($this->templateProperty === null) {
$obj = $this->obj();
if ($obj instanceof TemplateableInterface) {
$this->setTemplateProperty($obj->property('template_ident'));
} else {
throw new RuntimeException(sprintf(
'Storage property owner is not defined for "%s"',
get_class($this)
));
}
}
return $this->templateProperty;
} | [
"public",
"function",
"templateProperty",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"templateProperty",
"===",
"null",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"obj",
"(",
")",
";",
"if",
"(",
"$",
"obj",
"instanceof",
"TemplateableInterface",
")",
"{",
"$",
"this",
"->",
"setTemplateProperty",
"(",
"$",
"obj",
"->",
"property",
"(",
"'template_ident'",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Storage property owner is not defined for \"%s\"'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"templateProperty",
";",
"}"
]
| Retrieve form object's property for template controller choices.
@throws RuntimeException If the template property was not previously set.
@return PropertyInterface|null | [
"Retrieve",
"form",
"object",
"s",
"property",
"for",
"template",
"controller",
"choices",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/TemplateOptionsFormGroup.php#L198-L213 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Property/Display/ChoiceDisplay.php | ChoiceDisplay.displayVal | public function displayVal()
{
$prop = $this->p();
$val = $this->propertyVal();
if ($val !== null) {
return $prop->displayVal($val);
}
if ($prop->allowNull()) {
$nil = $this->emptyChoice();
return (string)$nil['label'];
}
return '';
} | php | public function displayVal()
{
$prop = $this->p();
$val = $this->propertyVal();
if ($val !== null) {
return $prop->displayVal($val);
}
if ($prop->allowNull()) {
$nil = $this->emptyChoice();
return (string)$nil['label'];
}
return '';
} | [
"public",
"function",
"displayVal",
"(",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"p",
"(",
")",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"propertyVal",
"(",
")",
";",
"if",
"(",
"$",
"val",
"!==",
"null",
")",
"{",
"return",
"$",
"prop",
"->",
"displayVal",
"(",
"$",
"val",
")",
";",
"}",
"if",
"(",
"$",
"prop",
"->",
"allowNull",
"(",
")",
")",
"{",
"$",
"nil",
"=",
"$",
"this",
"->",
"emptyChoice",
"(",
")",
";",
"return",
"(",
"string",
")",
"$",
"nil",
"[",
"'label'",
"]",
";",
"}",
"return",
"''",
";",
"}"
]
| Retrieve display value.
@return string | [
"Retrieve",
"display",
"value",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Display/ChoiceDisplay.php#L96-L111 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormWidget.php | FormWidget.addFormProperties | public function addFormProperties(array $properties)
{
foreach ($properties as $propertyIdent => $property) {
$this->addFormProperty($propertyIdent, $property);
}
return $this;
} | php | public function addFormProperties(array $properties)
{
foreach ($properties as $propertyIdent => $property) {
$this->addFormProperty($propertyIdent, $property);
}
return $this;
} | [
"public",
"function",
"addFormProperties",
"(",
"array",
"$",
"properties",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"propertyIdent",
"=>",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"addFormProperty",
"(",
"$",
"propertyIdent",
",",
"$",
"property",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add property controls to the form.
@param array $properties The form properties.
@return self | [
"Add",
"property",
"controls",
"to",
"the",
"form",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormWidget.php#L265-L272 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormWidget.php | FormWidget.formProperties | public function formProperties()
{
$sidebars = $this->sidebars;
if (!is_array($sidebars)) {
yield null;
} else {
foreach ($this->formProperties as $formProperty) {
if ($formProperty->active() === false) {
continue;
}
$GLOBALS['widget_template'] = $formProperty->inputType();
yield $formProperty->propertyIdent() => $formProperty;
$GLOBALS['widget_template'] = '';
}
}
} | php | public function formProperties()
{
$sidebars = $this->sidebars;
if (!is_array($sidebars)) {
yield null;
} else {
foreach ($this->formProperties as $formProperty) {
if ($formProperty->active() === false) {
continue;
}
$GLOBALS['widget_template'] = $formProperty->inputType();
yield $formProperty->propertyIdent() => $formProperty;
$GLOBALS['widget_template'] = '';
}
}
} | [
"public",
"function",
"formProperties",
"(",
")",
"{",
"$",
"sidebars",
"=",
"$",
"this",
"->",
"sidebars",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"sidebars",
")",
")",
"{",
"yield",
"null",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"formProperties",
"as",
"$",
"formProperty",
")",
"{",
"if",
"(",
"$",
"formProperty",
"->",
"active",
"(",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"$",
"formProperty",
"->",
"inputType",
"(",
")",
";",
"yield",
"$",
"formProperty",
"->",
"propertyIdent",
"(",
")",
"=>",
"$",
"formProperty",
";",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"''",
";",
"}",
"}",
"}"
]
| Yield the form's property controls.
@return \Generator | [
"Yield",
"the",
"form",
"s",
"property",
"controls",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormWidget.php#L310-L328 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormWidget.php | FormWidget.addHiddenProperties | public function addHiddenProperties(array $properties)
{
foreach ($properties as $propertyIdent => $property) {
$this->addHiddenProperty($propertyIdent, $property);
}
return $this;
} | php | public function addHiddenProperties(array $properties)
{
foreach ($properties as $propertyIdent => $property) {
$this->addHiddenProperty($propertyIdent, $property);
}
return $this;
} | [
"public",
"function",
"addHiddenProperties",
"(",
"array",
"$",
"properties",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"propertyIdent",
"=>",
"$",
"property",
")",
"{",
"$",
"this",
"->",
"addHiddenProperty",
"(",
"$",
"propertyIdent",
",",
"$",
"property",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add hidden property controls to the form.
@param array $properties The hidden form properties.
@return FormInterface Chainable | [
"Add",
"hidden",
"property",
"controls",
"to",
"the",
"form",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormWidget.php#L351-L358 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormWidget.php | FormWidget.addHiddenProperty | public function addHiddenProperty($propertyIdent, $formProperty)
{
if (!is_string($propertyIdent)) {
throw new InvalidArgumentException(
'Property ident must be a string'
);
}
if (is_array($formProperty)) {
$this->getOrCreateFormProperty($propertyIdent, $formProperty);
} elseif (!$formProperty instanceof FormPropertyWidget) {
throw new InvalidArgumentException(sprintf(
'Property must be an array or an instance of FormPropertyWidget, received %s',
is_object($formProperty) ? get_class($formProperty) : gettype($formProperty)
));
}
return $this;
} | php | public function addHiddenProperty($propertyIdent, $formProperty)
{
if (!is_string($propertyIdent)) {
throw new InvalidArgumentException(
'Property ident must be a string'
);
}
if (is_array($formProperty)) {
$this->getOrCreateFormProperty($propertyIdent, $formProperty);
} elseif (!$formProperty instanceof FormPropertyWidget) {
throw new InvalidArgumentException(sprintf(
'Property must be an array or an instance of FormPropertyWidget, received %s',
is_object($formProperty) ? get_class($formProperty) : gettype($formProperty)
));
}
return $this;
} | [
"public",
"function",
"addHiddenProperty",
"(",
"$",
"propertyIdent",
",",
"$",
"formProperty",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"propertyIdent",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Property ident must be a string'",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"formProperty",
")",
")",
"{",
"$",
"this",
"->",
"getOrCreateFormProperty",
"(",
"$",
"propertyIdent",
",",
"$",
"formProperty",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"formProperty",
"instanceof",
"FormPropertyWidget",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Property must be an array or an instance of FormPropertyWidget, received %s'",
",",
"is_object",
"(",
"$",
"formProperty",
")",
"?",
"get_class",
"(",
"$",
"formProperty",
")",
":",
"gettype",
"(",
"$",
"formProperty",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add a hidden property control to the form.
@param string $propertyIdent The property identifier.
@param array|FormPropertyInterface $formProperty The property object or structure.
@throws InvalidArgumentException If the identifier or the property is invalid.
@return FormInterface Chainable | [
"Add",
"a",
"hidden",
"property",
"control",
"to",
"the",
"form",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormWidget.php#L368-L386 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/FormWidget.php | FormWidget.hiddenProperties | public function hiddenProperties()
{
foreach ($this->hiddenProperties as $formProperty) {
if ($formProperty->active() === false) {
continue;
}
yield $formProperty->propertyIdent() => $formProperty;
}
} | php | public function hiddenProperties()
{
foreach ($this->hiddenProperties as $formProperty) {
if ($formProperty->active() === false) {
continue;
}
yield $formProperty->propertyIdent() => $formProperty;
}
} | [
"public",
"function",
"hiddenProperties",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"hiddenProperties",
"as",
"$",
"formProperty",
")",
"{",
"if",
"(",
"$",
"formProperty",
"->",
"active",
"(",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"yield",
"$",
"formProperty",
"->",
"propertyIdent",
"(",
")",
"=>",
"$",
"formProperty",
";",
"}",
"}"
]
| Yield the form's hidden property controls.
@return \Generator | [
"Yield",
"the",
"form",
"s",
"hidden",
"property",
"controls",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormWidget.php#L393-L402 | train |
acquia/commerce-manager | modules/acm_sku/src/AcquiaCommerce/SKUPluginBase.php | SKUPluginBase.getParentSku | public function getParentSku(SKU $sku) {
$static = &drupal_static(__FUNCTION__, []);
$langcode = $sku->language()->getId();
$sku_string = $sku->getSku();
if (isset($static[$langcode], $static[$langcode][$sku_string])) {
return $static[$langcode][$sku_string];
}
// Initialise with empty value.
$static[$langcode][$sku_string] = NULL;
$parent_skus = array_keys($this->getAllParentSkus($sku_string));
if (empty($parent_skus)) {
return NULL;
}
if (count($parent_skus) > 1) {
\Drupal::logger('acm_sku')->warning(
'Multiple parents found for SKU: @sku, parents: @parents',
[
'@parents' => implode(',', $parent_skus),
'@sku' => $sku_string,
]
);
}
foreach ($parent_skus as $parent_sku) {
$parent = SKU::loadFromSku($parent_sku, $langcode);
if ($parent instanceof SKU) {
$node = $this->getDisplayNode($parent, FALSE, FALSE);
if ($node instanceof Node) {
$static[$langcode][$sku_string] = $parent;
break;
}
}
}
return $static[$langcode][$sku_string];
} | php | public function getParentSku(SKU $sku) {
$static = &drupal_static(__FUNCTION__, []);
$langcode = $sku->language()->getId();
$sku_string = $sku->getSku();
if (isset($static[$langcode], $static[$langcode][$sku_string])) {
return $static[$langcode][$sku_string];
}
// Initialise with empty value.
$static[$langcode][$sku_string] = NULL;
$parent_skus = array_keys($this->getAllParentSkus($sku_string));
if (empty($parent_skus)) {
return NULL;
}
if (count($parent_skus) > 1) {
\Drupal::logger('acm_sku')->warning(
'Multiple parents found for SKU: @sku, parents: @parents',
[
'@parents' => implode(',', $parent_skus),
'@sku' => $sku_string,
]
);
}
foreach ($parent_skus as $parent_sku) {
$parent = SKU::loadFromSku($parent_sku, $langcode);
if ($parent instanceof SKU) {
$node = $this->getDisplayNode($parent, FALSE, FALSE);
if ($node instanceof Node) {
$static[$langcode][$sku_string] = $parent;
break;
}
}
}
return $static[$langcode][$sku_string];
} | [
"public",
"function",
"getParentSku",
"(",
"SKU",
"$",
"sku",
")",
"{",
"$",
"static",
"=",
"&",
"drupal_static",
"(",
"__FUNCTION__",
",",
"[",
"]",
")",
";",
"$",
"langcode",
"=",
"$",
"sku",
"->",
"language",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"sku_string",
"=",
"$",
"sku",
"->",
"getSku",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"static",
"[",
"$",
"langcode",
"]",
",",
"$",
"static",
"[",
"$",
"langcode",
"]",
"[",
"$",
"sku_string",
"]",
")",
")",
"{",
"return",
"$",
"static",
"[",
"$",
"langcode",
"]",
"[",
"$",
"sku_string",
"]",
";",
"}",
"// Initialise with empty value.",
"$",
"static",
"[",
"$",
"langcode",
"]",
"[",
"$",
"sku_string",
"]",
"=",
"NULL",
";",
"$",
"parent_skus",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"getAllParentSkus",
"(",
"$",
"sku_string",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parent_skus",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parent_skus",
")",
">",
"1",
")",
"{",
"\\",
"Drupal",
"::",
"logger",
"(",
"'acm_sku'",
")",
"->",
"warning",
"(",
"'Multiple parents found for SKU: @sku, parents: @parents'",
",",
"[",
"'@parents'",
"=>",
"implode",
"(",
"','",
",",
"$",
"parent_skus",
")",
",",
"'@sku'",
"=>",
"$",
"sku_string",
",",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"parent_skus",
"as",
"$",
"parent_sku",
")",
"{",
"$",
"parent",
"=",
"SKU",
"::",
"loadFromSku",
"(",
"$",
"parent_sku",
",",
"$",
"langcode",
")",
";",
"if",
"(",
"$",
"parent",
"instanceof",
"SKU",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getDisplayNode",
"(",
"$",
"parent",
",",
"FALSE",
",",
"FALSE",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
")",
"{",
"$",
"static",
"[",
"$",
"langcode",
"]",
"[",
"$",
"sku_string",
"]",
"=",
"$",
"parent",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"static",
"[",
"$",
"langcode",
"]",
"[",
"$",
"sku_string",
"]",
";",
"}"
]
| Get parent of current product.
@param \Drupal\acm_sku\Entity\SKU $sku
Current product.
@return \Drupal\acm_sku\Entity\SKU|null
Parent product or null if not found.
@throws \Exception | [
"Get",
"parent",
"of",
"current",
"product",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/AcquiaCommerce/SKUPluginBase.php#L201-L243 | train |
acquia/commerce-manager | modules/acm_sku/src/AcquiaCommerce/SKUPluginBase.php | SKUPluginBase.getAllParentSkus | public function getAllParentSkus(string $sku) {
$static = &drupal_static(__FUNCTION__, []);
if (isset($static[$sku])) {
return $static[$sku];
}
$query = $this->connection->select('acm_sku_field_data', 'acm_sku');
$query->addField('acm_sku', 'sku');
$query->addField('acm_sku', 'id');
$query->join('acm_sku__field_configured_skus', 'child_sku', 'acm_sku.id = child_sku.entity_id');
$query->condition('child_sku.field_configured_skus_value', $sku);
$static[$sku] = $query->execute()->fetchAllKeyed(0, 1) ?? [];
return $static[$sku];
} | php | public function getAllParentSkus(string $sku) {
$static = &drupal_static(__FUNCTION__, []);
if (isset($static[$sku])) {
return $static[$sku];
}
$query = $this->connection->select('acm_sku_field_data', 'acm_sku');
$query->addField('acm_sku', 'sku');
$query->addField('acm_sku', 'id');
$query->join('acm_sku__field_configured_skus', 'child_sku', 'acm_sku.id = child_sku.entity_id');
$query->condition('child_sku.field_configured_skus_value', $sku);
$static[$sku] = $query->execute()->fetchAllKeyed(0, 1) ?? [];
return $static[$sku];
} | [
"public",
"function",
"getAllParentSkus",
"(",
"string",
"$",
"sku",
")",
"{",
"$",
"static",
"=",
"&",
"drupal_static",
"(",
"__FUNCTION__",
",",
"[",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"static",
"[",
"$",
"sku",
"]",
")",
")",
"{",
"return",
"$",
"static",
"[",
"$",
"sku",
"]",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"connection",
"->",
"select",
"(",
"'acm_sku_field_data'",
",",
"'acm_sku'",
")",
";",
"$",
"query",
"->",
"addField",
"(",
"'acm_sku'",
",",
"'sku'",
")",
";",
"$",
"query",
"->",
"addField",
"(",
"'acm_sku'",
",",
"'id'",
")",
";",
"$",
"query",
"->",
"join",
"(",
"'acm_sku__field_configured_skus'",
",",
"'child_sku'",
",",
"'acm_sku.id = child_sku.entity_id'",
")",
";",
"$",
"query",
"->",
"condition",
"(",
"'child_sku.field_configured_skus_value'",
",",
"$",
"sku",
")",
";",
"$",
"static",
"[",
"$",
"sku",
"]",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAllKeyed",
"(",
"0",
",",
"1",
")",
"??",
"[",
"]",
";",
"return",
"$",
"static",
"[",
"$",
"sku",
"]",
";",
"}"
]
| Get all parent skus of a given sku.
@param string $sku
Sku string.
@return array
All parent skus with sku as key and id as value. | [
"Get",
"all",
"parent",
"skus",
"of",
"a",
"given",
"sku",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/AcquiaCommerce/SKUPluginBase.php#L402-L417 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Widget/CollectionMapWidget.php | CollectionMapWidget.mapObjects | public function mapObjects()
{
if ($this->mapObjects === null) {
$objType = $this->objType();
if (!$objType) {
throw new UnexpectedValueException(sprintf(
'%1$s cannot create collection map. Object type is not defined.',
get_class($this)
));
}
$loader = $this->collectionLoader();
$loader->setModel($this->proto());
$collectionConfig = $this->collectionConfig();
if (is_array($collectionConfig) && !empty($collectionConfig)) {
unset($collectionConfig['properties']);
$loader->setData($collectionConfig);
}
$callback = function(&$obj) {
$obj->mapInfoboxTemplate = $this->infoboxTemplate();
if ($this->latProperty() && $this->latProperty()) {
$obj->mapShowMarker = true;
$obj->mapLat = $this->getPropertyValue($obj, $this->latProperty());
$obj->mapLon = $this->getPropertyValue($obj, $this->lonProperty());
if (!$obj->mapLat || !$obj->mapLon) {
$obj = null;
}
} else {
$obj->mapShowMarker = false;
}
if ($this->pathProperty()) {
$mapPath = $this->getPropertyValue($obj, $this->pathProperty());
if ($mapPath) {
$obj->mapShowPath = true;
// Same type of coords.
$obj->mapPath = $this->formatPolygon($mapPath);
if (!$obj->mapPath) {
$obj = null;
}
} else {
$obj->mapShowPath = false;
}
}
if ($this->polygonProperty()) {
$mapPolygon = $this->getPropertyValue($obj, $this->polygonProperty());
if ($mapPolygon) {
$obj->mapShowPolygon = true;
$obj->mapPolygon = $this->formatPolygon($mapPolygon);
if (!$obj->mapPolygon) {
$obj = null;
}
} else {
$obj->mapShowPolygon = false;
}
}
};
$loader->setCallback($callback->bindTo($this));
$this->mapObjects = $loader->load();
}
foreach ($this->mapObjects as $obj) {
$GLOBALS['widget_template'] = $obj->mapInfoboxTemplate;
yield $obj;
$GLOBALS['widget_template'] = '';
}
} | php | public function mapObjects()
{
if ($this->mapObjects === null) {
$objType = $this->objType();
if (!$objType) {
throw new UnexpectedValueException(sprintf(
'%1$s cannot create collection map. Object type is not defined.',
get_class($this)
));
}
$loader = $this->collectionLoader();
$loader->setModel($this->proto());
$collectionConfig = $this->collectionConfig();
if (is_array($collectionConfig) && !empty($collectionConfig)) {
unset($collectionConfig['properties']);
$loader->setData($collectionConfig);
}
$callback = function(&$obj) {
$obj->mapInfoboxTemplate = $this->infoboxTemplate();
if ($this->latProperty() && $this->latProperty()) {
$obj->mapShowMarker = true;
$obj->mapLat = $this->getPropertyValue($obj, $this->latProperty());
$obj->mapLon = $this->getPropertyValue($obj, $this->lonProperty());
if (!$obj->mapLat || !$obj->mapLon) {
$obj = null;
}
} else {
$obj->mapShowMarker = false;
}
if ($this->pathProperty()) {
$mapPath = $this->getPropertyValue($obj, $this->pathProperty());
if ($mapPath) {
$obj->mapShowPath = true;
// Same type of coords.
$obj->mapPath = $this->formatPolygon($mapPath);
if (!$obj->mapPath) {
$obj = null;
}
} else {
$obj->mapShowPath = false;
}
}
if ($this->polygonProperty()) {
$mapPolygon = $this->getPropertyValue($obj, $this->polygonProperty());
if ($mapPolygon) {
$obj->mapShowPolygon = true;
$obj->mapPolygon = $this->formatPolygon($mapPolygon);
if (!$obj->mapPolygon) {
$obj = null;
}
} else {
$obj->mapShowPolygon = false;
}
}
};
$loader->setCallback($callback->bindTo($this));
$this->mapObjects = $loader->load();
}
foreach ($this->mapObjects as $obj) {
$GLOBALS['widget_template'] = $obj->mapInfoboxTemplate;
yield $obj;
$GLOBALS['widget_template'] = '';
}
} | [
"public",
"function",
"mapObjects",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"mapObjects",
"===",
"null",
")",
"{",
"$",
"objType",
"=",
"$",
"this",
"->",
"objType",
"(",
")",
";",
"if",
"(",
"!",
"$",
"objType",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'%1$s cannot create collection map. Object type is not defined.'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"$",
"loader",
"=",
"$",
"this",
"->",
"collectionLoader",
"(",
")",
";",
"$",
"loader",
"->",
"setModel",
"(",
"$",
"this",
"->",
"proto",
"(",
")",
")",
";",
"$",
"collectionConfig",
"=",
"$",
"this",
"->",
"collectionConfig",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"collectionConfig",
")",
"&&",
"!",
"empty",
"(",
"$",
"collectionConfig",
")",
")",
"{",
"unset",
"(",
"$",
"collectionConfig",
"[",
"'properties'",
"]",
")",
";",
"$",
"loader",
"->",
"setData",
"(",
"$",
"collectionConfig",
")",
";",
"}",
"$",
"callback",
"=",
"function",
"(",
"&",
"$",
"obj",
")",
"{",
"$",
"obj",
"->",
"mapInfoboxTemplate",
"=",
"$",
"this",
"->",
"infoboxTemplate",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"latProperty",
"(",
")",
"&&",
"$",
"this",
"->",
"latProperty",
"(",
")",
")",
"{",
"$",
"obj",
"->",
"mapShowMarker",
"=",
"true",
";",
"$",
"obj",
"->",
"mapLat",
"=",
"$",
"this",
"->",
"getPropertyValue",
"(",
"$",
"obj",
",",
"$",
"this",
"->",
"latProperty",
"(",
")",
")",
";",
"$",
"obj",
"->",
"mapLon",
"=",
"$",
"this",
"->",
"getPropertyValue",
"(",
"$",
"obj",
",",
"$",
"this",
"->",
"lonProperty",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"obj",
"->",
"mapLat",
"||",
"!",
"$",
"obj",
"->",
"mapLon",
")",
"{",
"$",
"obj",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"obj",
"->",
"mapShowMarker",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"pathProperty",
"(",
")",
")",
"{",
"$",
"mapPath",
"=",
"$",
"this",
"->",
"getPropertyValue",
"(",
"$",
"obj",
",",
"$",
"this",
"->",
"pathProperty",
"(",
")",
")",
";",
"if",
"(",
"$",
"mapPath",
")",
"{",
"$",
"obj",
"->",
"mapShowPath",
"=",
"true",
";",
"// Same type of coords.",
"$",
"obj",
"->",
"mapPath",
"=",
"$",
"this",
"->",
"formatPolygon",
"(",
"$",
"mapPath",
")",
";",
"if",
"(",
"!",
"$",
"obj",
"->",
"mapPath",
")",
"{",
"$",
"obj",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"obj",
"->",
"mapShowPath",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"polygonProperty",
"(",
")",
")",
"{",
"$",
"mapPolygon",
"=",
"$",
"this",
"->",
"getPropertyValue",
"(",
"$",
"obj",
",",
"$",
"this",
"->",
"polygonProperty",
"(",
")",
")",
";",
"if",
"(",
"$",
"mapPolygon",
")",
"{",
"$",
"obj",
"->",
"mapShowPolygon",
"=",
"true",
";",
"$",
"obj",
"->",
"mapPolygon",
"=",
"$",
"this",
"->",
"formatPolygon",
"(",
"$",
"mapPolygon",
")",
";",
"if",
"(",
"!",
"$",
"obj",
"->",
"mapPolygon",
")",
"{",
"$",
"obj",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"obj",
"->",
"mapShowPolygon",
"=",
"false",
";",
"}",
"}",
"}",
";",
"$",
"loader",
"->",
"setCallback",
"(",
"$",
"callback",
"->",
"bindTo",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"mapObjects",
"=",
"$",
"loader",
"->",
"load",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"mapObjects",
"as",
"$",
"obj",
")",
"{",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"$",
"obj",
"->",
"mapInfoboxTemplate",
";",
"yield",
"$",
"obj",
";",
"$",
"GLOBALS",
"[",
"'widget_template'",
"]",
"=",
"''",
";",
"}",
"}"
]
| Return all the objs with geographical information
@throws UnexpectedValueException If the object type of the colletion is missing.
@return Collection | [
"Return",
"all",
"the",
"objs",
"with",
"geographical",
"information"
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/CollectionMapWidget.php#L200-L275 | train |
acquia/commerce-manager | modules/acm_cart/src/MiniCartManager.php | MiniCartManager.getMiniCart | public function getMiniCart() {
$cart = $this->cartStorage->getCart(FALSE);
// Return empty cart in case no cart available in current session.
$output = [
'#theme' => 'acm_cart_mini_cart',
'#attached' => [
'library' => ['acm_cart/minicart'],
],
'#prefix' => '<div id="mini-cart-wrapper">',
'#suffix' => '</div><div id="cart_notification"></div>',
];
if (!$this->cartStorage->isEmpty()) {
$totals = $cart->totals();
// The grand total including discounts and taxes.
$grand_total = $totals['grand'] < 0 || $totals['grand'] == NULL ? 0 : $totals['grand'];
// Deduct shipping.
if (isset($totals['shipping']) && $grand_total) {
$grand_total -= $totals['shipping'];
}
$total = [
'#markup' => \Drupal::service('acm.i18n_helper')->formatPrice($grand_total),
];
// Use the template to render the HTML.
$output['#quantity'] = $cart->getCartItemsCount();
$output['#total'] = $total;
}
return $output;
} | php | public function getMiniCart() {
$cart = $this->cartStorage->getCart(FALSE);
// Return empty cart in case no cart available in current session.
$output = [
'#theme' => 'acm_cart_mini_cart',
'#attached' => [
'library' => ['acm_cart/minicart'],
],
'#prefix' => '<div id="mini-cart-wrapper">',
'#suffix' => '</div><div id="cart_notification"></div>',
];
if (!$this->cartStorage->isEmpty()) {
$totals = $cart->totals();
// The grand total including discounts and taxes.
$grand_total = $totals['grand'] < 0 || $totals['grand'] == NULL ? 0 : $totals['grand'];
// Deduct shipping.
if (isset($totals['shipping']) && $grand_total) {
$grand_total -= $totals['shipping'];
}
$total = [
'#markup' => \Drupal::service('acm.i18n_helper')->formatPrice($grand_total),
];
// Use the template to render the HTML.
$output['#quantity'] = $cart->getCartItemsCount();
$output['#total'] = $total;
}
return $output;
} | [
"public",
"function",
"getMiniCart",
"(",
")",
"{",
"$",
"cart",
"=",
"$",
"this",
"->",
"cartStorage",
"->",
"getCart",
"(",
"FALSE",
")",
";",
"// Return empty cart in case no cart available in current session.",
"$",
"output",
"=",
"[",
"'#theme'",
"=>",
"'acm_cart_mini_cart'",
",",
"'#attached'",
"=>",
"[",
"'library'",
"=>",
"[",
"'acm_cart/minicart'",
"]",
",",
"]",
",",
"'#prefix'",
"=>",
"'<div id=\"mini-cart-wrapper\">'",
",",
"'#suffix'",
"=>",
"'</div><div id=\"cart_notification\"></div>'",
",",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"cartStorage",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"totals",
"=",
"$",
"cart",
"->",
"totals",
"(",
")",
";",
"// The grand total including discounts and taxes.",
"$",
"grand_total",
"=",
"$",
"totals",
"[",
"'grand'",
"]",
"<",
"0",
"||",
"$",
"totals",
"[",
"'grand'",
"]",
"==",
"NULL",
"?",
"0",
":",
"$",
"totals",
"[",
"'grand'",
"]",
";",
"// Deduct shipping.",
"if",
"(",
"isset",
"(",
"$",
"totals",
"[",
"'shipping'",
"]",
")",
"&&",
"$",
"grand_total",
")",
"{",
"$",
"grand_total",
"-=",
"$",
"totals",
"[",
"'shipping'",
"]",
";",
"}",
"$",
"total",
"=",
"[",
"'#markup'",
"=>",
"\\",
"Drupal",
"::",
"service",
"(",
"'acm.i18n_helper'",
")",
"->",
"formatPrice",
"(",
"$",
"grand_total",
")",
",",
"]",
";",
"// Use the template to render the HTML.",
"$",
"output",
"[",
"'#quantity'",
"]",
"=",
"$",
"cart",
"->",
"getCartItemsCount",
"(",
")",
";",
"$",
"output",
"[",
"'#total'",
"]",
"=",
"$",
"total",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Helper function to get Mini cart. | [
"Helper",
"function",
"to",
"get",
"Mini",
"cart",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/MiniCartManager.php#L25-L59 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php | AdminServiceProvider.registerAdminServices | protected function registerAdminServices(Container $container)
{
/**
* The admin configset.
*
* @param Container $container The Pimple DI Container.
* @return AdminConfig
*/
$container['admin/config'] = function (Container $container) {
$appConfig = $container['config'];
// The `admin.json` file is not part of regular config
$extraConfigs = (array)$appConfig['admin_config'];
$moduleAdminConfigs = [];
foreach ($container['module/classes'] as $module) {
if (defined(sprintf('%s::ADMIN_CONFIG', $module))) {
$moduleAdminConfigs[] = $module::ADMIN_CONFIG;
};
}
if (!empty($moduleAdminConfigs)) {
$extraConfigs = array_merge(
$extraConfigs,
$moduleAdminConfigs
);
}
if (!empty($extraConfigs)) {
$basePath = $appConfig['base_path'];
foreach ($extraConfigs as $path) {
$appConfig->addFile($basePath.$path);
}
}
return new AdminConfig($appConfig['admin']);
};
if (!isset($container['admin/base-url'])) {
/**
* Base Admin URL as a PSR-7 UriInterface object for the current request
* or the Charcoal application.
*
* @param Container $container The Pimple DI Container.
* @return \Psr\Http\Message\UriInterface
*/
$container['admin/base-url'] = function (Container $container) {
$adminConfig = $container['admin/config'];
if (isset($adminConfig['base_url'])) {
$adminUrl = $adminConfig['base_url'];
} else {
$adminUrl = clone $container['base-url'];
if ($adminConfig['base_path']) {
$basePath = rtrim($adminUrl->getBasePath(), '/');
$adminPath = ltrim($adminConfig['base_path'], '/');
$adminUrl = $adminUrl->withBasePath($basePath.'/'.$adminPath);
}
}
$adminUrl = Uri::createFromString($adminUrl)->withUserInfo('');
/** Fix the base path */
$path = $adminUrl->getPath();
if ($path) {
$adminUrl = $adminUrl->withBasePath($path)->withPath('');
}
return $adminUrl;
};
}
} | php | protected function registerAdminServices(Container $container)
{
/**
* The admin configset.
*
* @param Container $container The Pimple DI Container.
* @return AdminConfig
*/
$container['admin/config'] = function (Container $container) {
$appConfig = $container['config'];
// The `admin.json` file is not part of regular config
$extraConfigs = (array)$appConfig['admin_config'];
$moduleAdminConfigs = [];
foreach ($container['module/classes'] as $module) {
if (defined(sprintf('%s::ADMIN_CONFIG', $module))) {
$moduleAdminConfigs[] = $module::ADMIN_CONFIG;
};
}
if (!empty($moduleAdminConfigs)) {
$extraConfigs = array_merge(
$extraConfigs,
$moduleAdminConfigs
);
}
if (!empty($extraConfigs)) {
$basePath = $appConfig['base_path'];
foreach ($extraConfigs as $path) {
$appConfig->addFile($basePath.$path);
}
}
return new AdminConfig($appConfig['admin']);
};
if (!isset($container['admin/base-url'])) {
/**
* Base Admin URL as a PSR-7 UriInterface object for the current request
* or the Charcoal application.
*
* @param Container $container The Pimple DI Container.
* @return \Psr\Http\Message\UriInterface
*/
$container['admin/base-url'] = function (Container $container) {
$adminConfig = $container['admin/config'];
if (isset($adminConfig['base_url'])) {
$adminUrl = $adminConfig['base_url'];
} else {
$adminUrl = clone $container['base-url'];
if ($adminConfig['base_path']) {
$basePath = rtrim($adminUrl->getBasePath(), '/');
$adminPath = ltrim($adminConfig['base_path'], '/');
$adminUrl = $adminUrl->withBasePath($basePath.'/'.$adminPath);
}
}
$adminUrl = Uri::createFromString($adminUrl)->withUserInfo('');
/** Fix the base path */
$path = $adminUrl->getPath();
if ($path) {
$adminUrl = $adminUrl->withBasePath($path)->withPath('');
}
return $adminUrl;
};
}
} | [
"protected",
"function",
"registerAdminServices",
"(",
"Container",
"$",
"container",
")",
"{",
"/**\n * The admin configset.\n *\n * @param Container $container The Pimple DI Container.\n * @return AdminConfig\n */",
"$",
"container",
"[",
"'admin/config'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"$",
"appConfig",
"=",
"$",
"container",
"[",
"'config'",
"]",
";",
"// The `admin.json` file is not part of regular config",
"$",
"extraConfigs",
"=",
"(",
"array",
")",
"$",
"appConfig",
"[",
"'admin_config'",
"]",
";",
"$",
"moduleAdminConfigs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"container",
"[",
"'module/classes'",
"]",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"defined",
"(",
"sprintf",
"(",
"'%s::ADMIN_CONFIG'",
",",
"$",
"module",
")",
")",
")",
"{",
"$",
"moduleAdminConfigs",
"[",
"]",
"=",
"$",
"module",
"::",
"ADMIN_CONFIG",
";",
"}",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"moduleAdminConfigs",
")",
")",
"{",
"$",
"extraConfigs",
"=",
"array_merge",
"(",
"$",
"extraConfigs",
",",
"$",
"moduleAdminConfigs",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"extraConfigs",
")",
")",
"{",
"$",
"basePath",
"=",
"$",
"appConfig",
"[",
"'base_path'",
"]",
";",
"foreach",
"(",
"$",
"extraConfigs",
"as",
"$",
"path",
")",
"{",
"$",
"appConfig",
"->",
"addFile",
"(",
"$",
"basePath",
".",
"$",
"path",
")",
";",
"}",
"}",
"return",
"new",
"AdminConfig",
"(",
"$",
"appConfig",
"[",
"'admin'",
"]",
")",
";",
"}",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"container",
"[",
"'admin/base-url'",
"]",
")",
")",
"{",
"/**\n * Base Admin URL as a PSR-7 UriInterface object for the current request\n * or the Charcoal application.\n *\n * @param Container $container The Pimple DI Container.\n * @return \\Psr\\Http\\Message\\UriInterface\n */",
"$",
"container",
"[",
"'admin/base-url'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"$",
"adminConfig",
"=",
"$",
"container",
"[",
"'admin/config'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"adminConfig",
"[",
"'base_url'",
"]",
")",
")",
"{",
"$",
"adminUrl",
"=",
"$",
"adminConfig",
"[",
"'base_url'",
"]",
";",
"}",
"else",
"{",
"$",
"adminUrl",
"=",
"clone",
"$",
"container",
"[",
"'base-url'",
"]",
";",
"if",
"(",
"$",
"adminConfig",
"[",
"'base_path'",
"]",
")",
"{",
"$",
"basePath",
"=",
"rtrim",
"(",
"$",
"adminUrl",
"->",
"getBasePath",
"(",
")",
",",
"'/'",
")",
";",
"$",
"adminPath",
"=",
"ltrim",
"(",
"$",
"adminConfig",
"[",
"'base_path'",
"]",
",",
"'/'",
")",
";",
"$",
"adminUrl",
"=",
"$",
"adminUrl",
"->",
"withBasePath",
"(",
"$",
"basePath",
".",
"'/'",
".",
"$",
"adminPath",
")",
";",
"}",
"}",
"$",
"adminUrl",
"=",
"Uri",
"::",
"createFromString",
"(",
"$",
"adminUrl",
")",
"->",
"withUserInfo",
"(",
"''",
")",
";",
"/** Fix the base path */",
"$",
"path",
"=",
"$",
"adminUrl",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"adminUrl",
"=",
"$",
"adminUrl",
"->",
"withBasePath",
"(",
"$",
"path",
")",
"->",
"withPath",
"(",
"''",
")",
";",
"}",
"return",
"$",
"adminUrl",
";",
"}",
";",
"}",
"}"
]
| Registers admin services.
@param Container $container The Pimple DI container.
@return void | [
"Registers",
"admin",
"services",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php#L104-L176 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php | AdminServiceProvider.registerMetadataExtensions | protected function registerMetadataExtensions(Container $container)
{
if (!isset($container['metadata/config'])) {
/**
* @return MetadataConfig
*/
$container['metadata/config'] = function () {
return new MetadataConfig();
};
}
/**
* Alters the application's metadata configset.
*
* This extension will duplicate each previously defined
* metadata include path to introduce an "admin" subdirectory
* which adds support for Admin-only metadata settings.
*
* For example, if a developer defines the following paths:
*
* ```json
* "paths": [
* "my-app/metadata/",
* "vendor/locomotivemtl/charcoal-cms/metadata/"
* ]
* ```
*
* The Admin's service provider will duplicate like so:
*
* ```json
* "paths": [
* "my-app/metadata/admin/",
* "my-app/metadata/",
* "vendor/locomotivemtl/charcoal-cms/metadata/admin/"
* "vendor/locomotivemtl/charcoal-cms/metadata/"
* ]
* ```
*
* Any data included from the "admin" subdirectory will override
* any "base" data that's been imported.
*
* @param MetadataConfig $metaConfig The metadata configset.
* @param Container $container The Pimple DI container.
* @return MetadataConfig
*/
$container->extend('metadata/config', function (MetadataConfig $metaConfig, Container $container) {
$adminConfig = $container['admin/config'];
$adminDir = '/'.trim($adminConfig['base_path'], '/');
$metaPaths = $metaConfig->paths();
$parsedPaths = [];
foreach ($metaPaths as $basePath) {
$adminPath = rtrim($basePath, '/').$adminDir;
array_push($parsedPaths, $adminPath, $basePath);
}
$metaConfig->setPaths($parsedPaths);
return $metaConfig;
});
} | php | protected function registerMetadataExtensions(Container $container)
{
if (!isset($container['metadata/config'])) {
/**
* @return MetadataConfig
*/
$container['metadata/config'] = function () {
return new MetadataConfig();
};
}
/**
* Alters the application's metadata configset.
*
* This extension will duplicate each previously defined
* metadata include path to introduce an "admin" subdirectory
* which adds support for Admin-only metadata settings.
*
* For example, if a developer defines the following paths:
*
* ```json
* "paths": [
* "my-app/metadata/",
* "vendor/locomotivemtl/charcoal-cms/metadata/"
* ]
* ```
*
* The Admin's service provider will duplicate like so:
*
* ```json
* "paths": [
* "my-app/metadata/admin/",
* "my-app/metadata/",
* "vendor/locomotivemtl/charcoal-cms/metadata/admin/"
* "vendor/locomotivemtl/charcoal-cms/metadata/"
* ]
* ```
*
* Any data included from the "admin" subdirectory will override
* any "base" data that's been imported.
*
* @param MetadataConfig $metaConfig The metadata configset.
* @param Container $container The Pimple DI container.
* @return MetadataConfig
*/
$container->extend('metadata/config', function (MetadataConfig $metaConfig, Container $container) {
$adminConfig = $container['admin/config'];
$adminDir = '/'.trim($adminConfig['base_path'], '/');
$metaPaths = $metaConfig->paths();
$parsedPaths = [];
foreach ($metaPaths as $basePath) {
$adminPath = rtrim($basePath, '/').$adminDir;
array_push($parsedPaths, $adminPath, $basePath);
}
$metaConfig->setPaths($parsedPaths);
return $metaConfig;
});
} | [
"protected",
"function",
"registerMetadataExtensions",
"(",
"Container",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"container",
"[",
"'metadata/config'",
"]",
")",
")",
"{",
"/**\n * @return MetadataConfig\n */",
"$",
"container",
"[",
"'metadata/config'",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"MetadataConfig",
"(",
")",
";",
"}",
";",
"}",
"/**\n * Alters the application's metadata configset.\n *\n * This extension will duplicate each previously defined\n * metadata include path to introduce an \"admin\" subdirectory\n * which adds support for Admin-only metadata settings.\n *\n * For example, if a developer defines the following paths:\n *\n * ```json\n * \"paths\": [\n * \"my-app/metadata/\",\n * \"vendor/locomotivemtl/charcoal-cms/metadata/\"\n * ]\n * ```\n *\n * The Admin's service provider will duplicate like so:\n *\n * ```json\n * \"paths\": [\n * \"my-app/metadata/admin/\",\n * \"my-app/metadata/\",\n * \"vendor/locomotivemtl/charcoal-cms/metadata/admin/\"\n * \"vendor/locomotivemtl/charcoal-cms/metadata/\"\n * ]\n * ```\n *\n * Any data included from the \"admin\" subdirectory will override\n * any \"base\" data that's been imported.\n *\n * @param MetadataConfig $metaConfig The metadata configset.\n * @param Container $container The Pimple DI container.\n * @return MetadataConfig\n */",
"$",
"container",
"->",
"extend",
"(",
"'metadata/config'",
",",
"function",
"(",
"MetadataConfig",
"$",
"metaConfig",
",",
"Container",
"$",
"container",
")",
"{",
"$",
"adminConfig",
"=",
"$",
"container",
"[",
"'admin/config'",
"]",
";",
"$",
"adminDir",
"=",
"'/'",
".",
"trim",
"(",
"$",
"adminConfig",
"[",
"'base_path'",
"]",
",",
"'/'",
")",
";",
"$",
"metaPaths",
"=",
"$",
"metaConfig",
"->",
"paths",
"(",
")",
";",
"$",
"parsedPaths",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"metaPaths",
"as",
"$",
"basePath",
")",
"{",
"$",
"adminPath",
"=",
"rtrim",
"(",
"$",
"basePath",
",",
"'/'",
")",
".",
"$",
"adminDir",
";",
"array_push",
"(",
"$",
"parsedPaths",
",",
"$",
"adminPath",
",",
"$",
"basePath",
")",
";",
"}",
"$",
"metaConfig",
"->",
"setPaths",
"(",
"$",
"parsedPaths",
")",
";",
"return",
"$",
"metaConfig",
";",
"}",
")",
";",
"}"
]
| Registers metadata extensions.
@see \Charcoal\Model\ServiceProvider\ModelServiceProvider
@param Container $container The Pimple DI container.
@return void | [
"Registers",
"metadata",
"extensions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php#L185-L246 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php | AdminServiceProvider.registerAuthExtensions | protected function registerAuthExtensions(Container $container)
{
/**
* @param Container $container The Pimple DI Container.
* @return Authenticator
*/
$container['admin/authenticator'] = function (Container $container) {
return new Authenticator([
'logger' => $container['logger'],
'user_type' => User::class,
'user_factory' => $container['model/factory'],
'token_type' => AuthToken::class,
'token_factory' => $container['model/factory']
]);
};
/**
* For 'charcoal-ui'
*
* @todo Do this right!
* @param Container $container The Pimple DI Container.
* @return Authenticator
*/
$container['authenticator'] = function (Container $container) {
return $container['admin/authenticator'];
};
/**
* @param Container $container The Pimple DI container.
* @return Authorizer
*/
$container['admin/authorizer'] = function (Container $container) {
return new Authorizer([
'logger' => $container['logger'],
'acl' => $container['admin/acl'],
'resource' => 'admin'
]);
};
/**
* For 'charcoal-ui'
*
* @todo Do this right!
* @param Container $container The Pimple DI Container.
* @return Authorizer
*/
$container['authorizer'] = function (Container $container) {
return $container['admin/authorizer'];
};
} | php | protected function registerAuthExtensions(Container $container)
{
/**
* @param Container $container The Pimple DI Container.
* @return Authenticator
*/
$container['admin/authenticator'] = function (Container $container) {
return new Authenticator([
'logger' => $container['logger'],
'user_type' => User::class,
'user_factory' => $container['model/factory'],
'token_type' => AuthToken::class,
'token_factory' => $container['model/factory']
]);
};
/**
* For 'charcoal-ui'
*
* @todo Do this right!
* @param Container $container The Pimple DI Container.
* @return Authenticator
*/
$container['authenticator'] = function (Container $container) {
return $container['admin/authenticator'];
};
/**
* @param Container $container The Pimple DI container.
* @return Authorizer
*/
$container['admin/authorizer'] = function (Container $container) {
return new Authorizer([
'logger' => $container['logger'],
'acl' => $container['admin/acl'],
'resource' => 'admin'
]);
};
/**
* For 'charcoal-ui'
*
* @todo Do this right!
* @param Container $container The Pimple DI Container.
* @return Authorizer
*/
$container['authorizer'] = function (Container $container) {
return $container['admin/authorizer'];
};
} | [
"protected",
"function",
"registerAuthExtensions",
"(",
"Container",
"$",
"container",
")",
"{",
"/**\n * @param Container $container The Pimple DI Container.\n * @return Authenticator\n */",
"$",
"container",
"[",
"'admin/authenticator'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"Authenticator",
"(",
"[",
"'logger'",
"=>",
"$",
"container",
"[",
"'logger'",
"]",
",",
"'user_type'",
"=>",
"User",
"::",
"class",
",",
"'user_factory'",
"=>",
"$",
"container",
"[",
"'model/factory'",
"]",
",",
"'token_type'",
"=>",
"AuthToken",
"::",
"class",
",",
"'token_factory'",
"=>",
"$",
"container",
"[",
"'model/factory'",
"]",
"]",
")",
";",
"}",
";",
"/**\n * For 'charcoal-ui'\n *\n * @todo Do this right!\n * @param Container $container The Pimple DI Container.\n * @return Authenticator\n */",
"$",
"container",
"[",
"'authenticator'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"[",
"'admin/authenticator'",
"]",
";",
"}",
";",
"/**\n * @param Container $container The Pimple DI container.\n * @return Authorizer\n */",
"$",
"container",
"[",
"'admin/authorizer'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"Authorizer",
"(",
"[",
"'logger'",
"=>",
"$",
"container",
"[",
"'logger'",
"]",
",",
"'acl'",
"=>",
"$",
"container",
"[",
"'admin/acl'",
"]",
",",
"'resource'",
"=>",
"'admin'",
"]",
")",
";",
"}",
";",
"/**\n * For 'charcoal-ui'\n *\n * @todo Do this right!\n * @param Container $container The Pimple DI Container.\n * @return Authorizer\n */",
"$",
"container",
"[",
"'authorizer'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"[",
"'admin/authorizer'",
"]",
";",
"}",
";",
"}"
]
| Registers user-authentication extensions.
@param Container $container The Pimple DI container.
@return void | [
"Registers",
"user",
"-",
"authentication",
"extensions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php#L254-L303 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php | AdminServiceProvider.registerViewExtensions | protected function registerViewExtensions(Container $container)
{
if (!isset($container['view/mustache/helpers'])) {
$container['view/mustache/helpers'] = function () {
return [];
};
}
/**
* Extend helpers for the Mustache Engine
*
* @return array
*/
$container->extend('view/mustache/helpers', function (array $helpers, Container $container) {
$adminUrl = $container['admin/base-url'];
$urls = [
/**
* Alias of "siteUrl"
*
* @return UriInterface|null
*/
'adminUrl' => $adminUrl,
/**
* Prepend the administration-area URI to the given path.
*
* @see \Charcoal\App\ServiceProvider\AppServiceProvider::registerViewServices()
* @param string $uri A URI path to wrap.
* @return UriInterface|null
*/
'withAdminUrl' => function ($uri, LambdaHelper $helper = null) use ($adminUrl) {
if ($helper) {
$uri = $helper->render($uri);
}
$uri = strval($uri);
if ($uri === '') {
$uri = $adminUrl->withPath('');
} else {
$parts = parse_url($uri);
if (!isset($parts['scheme'])) {
if (!in_array($uri[0], ['/', '#', '?'])) {
$path = isset($parts['path']) ? ltrim($parts['path'], '/') : '';
$query = isset($parts['query']) ? $parts['query'] : '';
$hash = isset($parts['fragment']) ? $parts['fragment'] : '';
return $adminUrl->withPath($path)
->withQuery($query)
->withFragment($hash);
}
}
}
return $uri;
}
];
return array_merge($helpers, $urls);
});
} | php | protected function registerViewExtensions(Container $container)
{
if (!isset($container['view/mustache/helpers'])) {
$container['view/mustache/helpers'] = function () {
return [];
};
}
/**
* Extend helpers for the Mustache Engine
*
* @return array
*/
$container->extend('view/mustache/helpers', function (array $helpers, Container $container) {
$adminUrl = $container['admin/base-url'];
$urls = [
/**
* Alias of "siteUrl"
*
* @return UriInterface|null
*/
'adminUrl' => $adminUrl,
/**
* Prepend the administration-area URI to the given path.
*
* @see \Charcoal\App\ServiceProvider\AppServiceProvider::registerViewServices()
* @param string $uri A URI path to wrap.
* @return UriInterface|null
*/
'withAdminUrl' => function ($uri, LambdaHelper $helper = null) use ($adminUrl) {
if ($helper) {
$uri = $helper->render($uri);
}
$uri = strval($uri);
if ($uri === '') {
$uri = $adminUrl->withPath('');
} else {
$parts = parse_url($uri);
if (!isset($parts['scheme'])) {
if (!in_array($uri[0], ['/', '#', '?'])) {
$path = isset($parts['path']) ? ltrim($parts['path'], '/') : '';
$query = isset($parts['query']) ? $parts['query'] : '';
$hash = isset($parts['fragment']) ? $parts['fragment'] : '';
return $adminUrl->withPath($path)
->withQuery($query)
->withFragment($hash);
}
}
}
return $uri;
}
];
return array_merge($helpers, $urls);
});
} | [
"protected",
"function",
"registerViewExtensions",
"(",
"Container",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"container",
"[",
"'view/mustache/helpers'",
"]",
")",
")",
"{",
"$",
"container",
"[",
"'view/mustache/helpers'",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"[",
"]",
";",
"}",
";",
"}",
"/**\n * Extend helpers for the Mustache Engine\n *\n * @return array\n */",
"$",
"container",
"->",
"extend",
"(",
"'view/mustache/helpers'",
",",
"function",
"(",
"array",
"$",
"helpers",
",",
"Container",
"$",
"container",
")",
"{",
"$",
"adminUrl",
"=",
"$",
"container",
"[",
"'admin/base-url'",
"]",
";",
"$",
"urls",
"=",
"[",
"/**\n * Alias of \"siteUrl\"\n *\n * @return UriInterface|null\n */",
"'adminUrl'",
"=>",
"$",
"adminUrl",
",",
"/**\n * Prepend the administration-area URI to the given path.\n *\n * @see \\Charcoal\\App\\ServiceProvider\\AppServiceProvider::registerViewServices()\n * @param string $uri A URI path to wrap.\n * @return UriInterface|null\n */",
"'withAdminUrl'",
"=>",
"function",
"(",
"$",
"uri",
",",
"LambdaHelper",
"$",
"helper",
"=",
"null",
")",
"use",
"(",
"$",
"adminUrl",
")",
"{",
"if",
"(",
"$",
"helper",
")",
"{",
"$",
"uri",
"=",
"$",
"helper",
"->",
"render",
"(",
"$",
"uri",
")",
";",
"}",
"$",
"uri",
"=",
"strval",
"(",
"$",
"uri",
")",
";",
"if",
"(",
"$",
"uri",
"===",
"''",
")",
"{",
"$",
"uri",
"=",
"$",
"adminUrl",
"->",
"withPath",
"(",
"''",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"uri",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"parts",
"[",
"'scheme'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"uri",
"[",
"0",
"]",
",",
"[",
"'/'",
",",
"'#'",
",",
"'?'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'path'",
"]",
")",
"?",
"ltrim",
"(",
"$",
"parts",
"[",
"'path'",
"]",
",",
"'/'",
")",
":",
"''",
";",
"$",
"query",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
"?",
"$",
"parts",
"[",
"'query'",
"]",
":",
"''",
";",
"$",
"hash",
"=",
"isset",
"(",
"$",
"parts",
"[",
"'fragment'",
"]",
")",
"?",
"$",
"parts",
"[",
"'fragment'",
"]",
":",
"''",
";",
"return",
"$",
"adminUrl",
"->",
"withPath",
"(",
"$",
"path",
")",
"->",
"withQuery",
"(",
"$",
"query",
")",
"->",
"withFragment",
"(",
"$",
"hash",
")",
";",
"}",
"}",
"}",
"return",
"$",
"uri",
";",
"}",
"]",
";",
"return",
"array_merge",
"(",
"$",
"helpers",
",",
"$",
"urls",
")",
";",
"}",
")",
";",
"}"
]
| Registers view extensions.
@param Container $container The Pimple DI container.
@return void | [
"Registers",
"view",
"extensions",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php#L311-L370 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php | AdminServiceProvider.registerFactoryServices | protected function registerFactoryServices(Container $container)
{
/**
* @param Container $container The Pimple DI container.
* @return FactoryInterface
*/
$container['property/input/factory'] = function (Container $container) {
return new Factory([
'base_class' => PropertyInputInterface::class,
'arguments' => [[
'container' => $container,
'logger' => $container['logger']
]],
'resolver_options' => [
'suffix' => 'Input'
]
]);
};
/**
* @param Container $container The Pimple DI container.
* @return FactoryInterface
*/
$container['property/display/factory'] = function (Container $container) {
return new Factory([
'base_class' => PropertyDisplayInterface::class,
'arguments' => [[
'container' => $container,
'logger' => $container['logger']
]],
'resolver_options' => [
'suffix' => 'Display'
]
]);
};
/**
* @param Container $container A Pimple DI container.
* @return FactoryInterface
*/
$container['secondary-menu/group/factory'] = function (Container $container) {
return new Factory([
'base_class' => SecondaryMenuGroupInterface::class,
'default_class' => GenericSecondaryMenuGroup::class,
'arguments' => [[
'container' => $container,
'logger' => $container['logger'],
'view' => $container['view'],
'layout_builder' => $container['layout/builder']
]],
'resolver_options' => [
'suffix' => 'SecondaryMenuGroup'
]
]);
};
} | php | protected function registerFactoryServices(Container $container)
{
/**
* @param Container $container The Pimple DI container.
* @return FactoryInterface
*/
$container['property/input/factory'] = function (Container $container) {
return new Factory([
'base_class' => PropertyInputInterface::class,
'arguments' => [[
'container' => $container,
'logger' => $container['logger']
]],
'resolver_options' => [
'suffix' => 'Input'
]
]);
};
/**
* @param Container $container The Pimple DI container.
* @return FactoryInterface
*/
$container['property/display/factory'] = function (Container $container) {
return new Factory([
'base_class' => PropertyDisplayInterface::class,
'arguments' => [[
'container' => $container,
'logger' => $container['logger']
]],
'resolver_options' => [
'suffix' => 'Display'
]
]);
};
/**
* @param Container $container A Pimple DI container.
* @return FactoryInterface
*/
$container['secondary-menu/group/factory'] = function (Container $container) {
return new Factory([
'base_class' => SecondaryMenuGroupInterface::class,
'default_class' => GenericSecondaryMenuGroup::class,
'arguments' => [[
'container' => $container,
'logger' => $container['logger'],
'view' => $container['view'],
'layout_builder' => $container['layout/builder']
]],
'resolver_options' => [
'suffix' => 'SecondaryMenuGroup'
]
]);
};
} | [
"protected",
"function",
"registerFactoryServices",
"(",
"Container",
"$",
"container",
")",
"{",
"/**\n * @param Container $container The Pimple DI container.\n * @return FactoryInterface\n */",
"$",
"container",
"[",
"'property/input/factory'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"Factory",
"(",
"[",
"'base_class'",
"=>",
"PropertyInputInterface",
"::",
"class",
",",
"'arguments'",
"=>",
"[",
"[",
"'container'",
"=>",
"$",
"container",
",",
"'logger'",
"=>",
"$",
"container",
"[",
"'logger'",
"]",
"]",
"]",
",",
"'resolver_options'",
"=>",
"[",
"'suffix'",
"=>",
"'Input'",
"]",
"]",
")",
";",
"}",
";",
"/**\n * @param Container $container The Pimple DI container.\n * @return FactoryInterface\n */",
"$",
"container",
"[",
"'property/display/factory'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"Factory",
"(",
"[",
"'base_class'",
"=>",
"PropertyDisplayInterface",
"::",
"class",
",",
"'arguments'",
"=>",
"[",
"[",
"'container'",
"=>",
"$",
"container",
",",
"'logger'",
"=>",
"$",
"container",
"[",
"'logger'",
"]",
"]",
"]",
",",
"'resolver_options'",
"=>",
"[",
"'suffix'",
"=>",
"'Display'",
"]",
"]",
")",
";",
"}",
";",
"/**\n * @param Container $container A Pimple DI container.\n * @return FactoryInterface\n */",
"$",
"container",
"[",
"'secondary-menu/group/factory'",
"]",
"=",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"Factory",
"(",
"[",
"'base_class'",
"=>",
"SecondaryMenuGroupInterface",
"::",
"class",
",",
"'default_class'",
"=>",
"GenericSecondaryMenuGroup",
"::",
"class",
",",
"'arguments'",
"=>",
"[",
"[",
"'container'",
"=>",
"$",
"container",
",",
"'logger'",
"=>",
"$",
"container",
"[",
"'logger'",
"]",
",",
"'view'",
"=>",
"$",
"container",
"[",
"'view'",
"]",
",",
"'layout_builder'",
"=>",
"$",
"container",
"[",
"'layout/builder'",
"]",
"]",
"]",
",",
"'resolver_options'",
"=>",
"[",
"'suffix'",
"=>",
"'SecondaryMenuGroup'",
"]",
"]",
")",
";",
"}",
";",
"}"
]
| Registers the admin factories.
@param Container $container The Pimple DI container.
@return void | [
"Registers",
"the",
"admin",
"factories",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/ServiceProvider/AdminServiceProvider.php#L446-L501 | train |
acquia/commerce-manager | modules/acm_sku/src/SKUFieldsManager.php | SKUFieldsManager.addFields | public function addFields() {
$this->logger->info('addFields() invoked to add newly added base fields to SKU.');
// Get all the additional fields from all custom modules.
$fields = $this->getAllCustomFields();
// Store the fields in config.
$config = $this->configFactory->getEditable(self::BASE_FIELD_ADDITIONS_CONFIG);
$existing_fields = $config->getRawData();
$fields = array_diff_key($fields, $existing_fields);
$existing_fields = array_merge($existing_fields, $fields);
$config->setData($existing_fields)->save();
if ($fields) {
$this->logger->info('Adding new fields %fields.', [
'%fields' => json_encode($fields),
]);
// Apply entity updates, we will read from config and add/update fields.
$this->entityDefinitionUpdateManager->applyUpdates();
// Allow other modules to take some action after the fields are added.
$this->moduleHandler->invokeAll('acm_sku_base_fields_updated', [$fields, 'add']);
}
else {
$this->logger->warning('No new fields found to add.');
}
} | php | public function addFields() {
$this->logger->info('addFields() invoked to add newly added base fields to SKU.');
// Get all the additional fields from all custom modules.
$fields = $this->getAllCustomFields();
// Store the fields in config.
$config = $this->configFactory->getEditable(self::BASE_FIELD_ADDITIONS_CONFIG);
$existing_fields = $config->getRawData();
$fields = array_diff_key($fields, $existing_fields);
$existing_fields = array_merge($existing_fields, $fields);
$config->setData($existing_fields)->save();
if ($fields) {
$this->logger->info('Adding new fields %fields.', [
'%fields' => json_encode($fields),
]);
// Apply entity updates, we will read from config and add/update fields.
$this->entityDefinitionUpdateManager->applyUpdates();
// Allow other modules to take some action after the fields are added.
$this->moduleHandler->invokeAll('acm_sku_base_fields_updated', [$fields, 'add']);
}
else {
$this->logger->warning('No new fields found to add.');
}
} | [
"public",
"function",
"addFields",
"(",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'addFields() invoked to add newly added base fields to SKU.'",
")",
";",
"// Get all the additional fields from all custom modules.",
"$",
"fields",
"=",
"$",
"this",
"->",
"getAllCustomFields",
"(",
")",
";",
"// Store the fields in config.",
"$",
"config",
"=",
"$",
"this",
"->",
"configFactory",
"->",
"getEditable",
"(",
"self",
"::",
"BASE_FIELD_ADDITIONS_CONFIG",
")",
";",
"$",
"existing_fields",
"=",
"$",
"config",
"->",
"getRawData",
"(",
")",
";",
"$",
"fields",
"=",
"array_diff_key",
"(",
"$",
"fields",
",",
"$",
"existing_fields",
")",
";",
"$",
"existing_fields",
"=",
"array_merge",
"(",
"$",
"existing_fields",
",",
"$",
"fields",
")",
";",
"$",
"config",
"->",
"setData",
"(",
"$",
"existing_fields",
")",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"fields",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Adding new fields %fields.'",
",",
"[",
"'%fields'",
"=>",
"json_encode",
"(",
"$",
"fields",
")",
",",
"]",
")",
";",
"// Apply entity updates, we will read from config and add/update fields.",
"$",
"this",
"->",
"entityDefinitionUpdateManager",
"->",
"applyUpdates",
"(",
")",
";",
"// Allow other modules to take some action after the fields are added.",
"$",
"this",
"->",
"moduleHandler",
"->",
"invokeAll",
"(",
"'acm_sku_base_fields_updated'",
",",
"[",
"$",
"fields",
",",
"'add'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"'No new fields found to add.'",
")",
";",
"}",
"}"
]
| Function to add all new field definitions from custom modules to SKU Base. | [
"Function",
"to",
"add",
"all",
"new",
"field",
"definitions",
"from",
"custom",
"modules",
"to",
"SKU",
"Base",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/SKUFieldsManager.php#L84-L112 | train |
acquia/commerce-manager | modules/acm_sku/src/SKUFieldsManager.php | SKUFieldsManager.removeField | public function removeField($field_code) {
$config = $this->configFactory->getEditable(self::BASE_FIELD_ADDITIONS_CONFIG);
$fields = $config->getRawData();
if (!isset($fields[$field_code])) {
return;
}
$field = $fields[$field_code];
unset($fields[$field_code]);
$config->setData($fields)->save();
$this->entityTypeManager->clearCachedDefinitions();
$this->entityDefinitionUpdateManager->applyUpdates();
$fields_removed = [
$field_code => $field,
];
$this->moduleHandler->invokeAll('acm_sku_base_fields_updated', [$fields_removed, 'remove']);
} | php | public function removeField($field_code) {
$config = $this->configFactory->getEditable(self::BASE_FIELD_ADDITIONS_CONFIG);
$fields = $config->getRawData();
if (!isset($fields[$field_code])) {
return;
}
$field = $fields[$field_code];
unset($fields[$field_code]);
$config->setData($fields)->save();
$this->entityTypeManager->clearCachedDefinitions();
$this->entityDefinitionUpdateManager->applyUpdates();
$fields_removed = [
$field_code => $field,
];
$this->moduleHandler->invokeAll('acm_sku_base_fields_updated', [$fields_removed, 'remove']);
} | [
"public",
"function",
"removeField",
"(",
"$",
"field_code",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"configFactory",
"->",
"getEditable",
"(",
"self",
"::",
"BASE_FIELD_ADDITIONS_CONFIG",
")",
";",
"$",
"fields",
"=",
"$",
"config",
"->",
"getRawData",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"fields",
"[",
"$",
"field_code",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"field",
"=",
"$",
"fields",
"[",
"$",
"field_code",
"]",
";",
"unset",
"(",
"$",
"fields",
"[",
"$",
"field_code",
"]",
")",
";",
"$",
"config",
"->",
"setData",
"(",
"$",
"fields",
")",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"entityTypeManager",
"->",
"clearCachedDefinitions",
"(",
")",
";",
"$",
"this",
"->",
"entityDefinitionUpdateManager",
"->",
"applyUpdates",
"(",
")",
";",
"$",
"fields_removed",
"=",
"[",
"$",
"field_code",
"=>",
"$",
"field",
",",
"]",
";",
"$",
"this",
"->",
"moduleHandler",
"->",
"invokeAll",
"(",
"'acm_sku_base_fields_updated'",
",",
"[",
"$",
"fields_removed",
",",
"'remove'",
"]",
")",
";",
"}"
]
| Remove base field from SKU entity.
Note: Calling function needs to take care of clearing data.
@param string $field_code
Field code to remove. | [
"Remove",
"base",
"field",
"from",
"SKU",
"entity",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/SKUFieldsManager.php#L122-L142 | train |
acquia/commerce-manager | modules/acm_sku/src/SKUFieldsManager.php | SKUFieldsManager.updateFieldMetaInfo | public function updateFieldMetaInfo($field_code, array $field) {
$config = $this->configFactory->getEditable(self::BASE_FIELD_ADDITIONS_CONFIG);
$existing_fields = $config->getRawData();
if (empty($existing_fields[$field_code])) {
throw new \Exception('Field not available, try adding it first.');
}
// Checks to avoid errors.
$field_structure_info = [
'type',
'cardinality',
];
foreach ($field_structure_info as $info) {
if (isset($field[$info]) && $field['type'] != $existing_fields[$field_code]['type']) {
throw new \Exception('Can not modify field structure.');
}
}
// Need to apply entity updates for following.
$apply_updates = FALSE;
$field_labels_info = [
'label',
'description',
'visible_view',
'visible_form',
'weight',
];
foreach ($field_labels_info as $info) {
if (isset($field[$info]) && $field['type'] != $existing_fields[$field_code]['type']) {
$apply_updates = TRUE;
break;
}
}
$existing_fields[$field_code] = array_replace($existing_fields[$field_code], $field);
$config->setData($existing_fields)->save();
if ($apply_updates) {
$this->entityDefinitionUpdateManager->applyUpdates();
}
} | php | public function updateFieldMetaInfo($field_code, array $field) {
$config = $this->configFactory->getEditable(self::BASE_FIELD_ADDITIONS_CONFIG);
$existing_fields = $config->getRawData();
if (empty($existing_fields[$field_code])) {
throw new \Exception('Field not available, try adding it first.');
}
// Checks to avoid errors.
$field_structure_info = [
'type',
'cardinality',
];
foreach ($field_structure_info as $info) {
if (isset($field[$info]) && $field['type'] != $existing_fields[$field_code]['type']) {
throw new \Exception('Can not modify field structure.');
}
}
// Need to apply entity updates for following.
$apply_updates = FALSE;
$field_labels_info = [
'label',
'description',
'visible_view',
'visible_form',
'weight',
];
foreach ($field_labels_info as $info) {
if (isset($field[$info]) && $field['type'] != $existing_fields[$field_code]['type']) {
$apply_updates = TRUE;
break;
}
}
$existing_fields[$field_code] = array_replace($existing_fields[$field_code], $field);
$config->setData($existing_fields)->save();
if ($apply_updates) {
$this->entityDefinitionUpdateManager->applyUpdates();
}
} | [
"public",
"function",
"updateFieldMetaInfo",
"(",
"$",
"field_code",
",",
"array",
"$",
"field",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"configFactory",
"->",
"getEditable",
"(",
"self",
"::",
"BASE_FIELD_ADDITIONS_CONFIG",
")",
";",
"$",
"existing_fields",
"=",
"$",
"config",
"->",
"getRawData",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"existing_fields",
"[",
"$",
"field_code",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Field not available, try adding it first.'",
")",
";",
"}",
"// Checks to avoid errors.",
"$",
"field_structure_info",
"=",
"[",
"'type'",
",",
"'cardinality'",
",",
"]",
";",
"foreach",
"(",
"$",
"field_structure_info",
"as",
"$",
"info",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"$",
"info",
"]",
")",
"&&",
"$",
"field",
"[",
"'type'",
"]",
"!=",
"$",
"existing_fields",
"[",
"$",
"field_code",
"]",
"[",
"'type'",
"]",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Can not modify field structure.'",
")",
";",
"}",
"}",
"// Need to apply entity updates for following.",
"$",
"apply_updates",
"=",
"FALSE",
";",
"$",
"field_labels_info",
"=",
"[",
"'label'",
",",
"'description'",
",",
"'visible_view'",
",",
"'visible_form'",
",",
"'weight'",
",",
"]",
";",
"foreach",
"(",
"$",
"field_labels_info",
"as",
"$",
"info",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"$",
"info",
"]",
")",
"&&",
"$",
"field",
"[",
"'type'",
"]",
"!=",
"$",
"existing_fields",
"[",
"$",
"field_code",
"]",
"[",
"'type'",
"]",
")",
"{",
"$",
"apply_updates",
"=",
"TRUE",
";",
"break",
";",
"}",
"}",
"$",
"existing_fields",
"[",
"$",
"field_code",
"]",
"=",
"array_replace",
"(",
"$",
"existing_fields",
"[",
"$",
"field_code",
"]",
",",
"$",
"field",
")",
";",
"$",
"config",
"->",
"setData",
"(",
"$",
"existing_fields",
")",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"apply_updates",
")",
"{",
"$",
"this",
"->",
"entityDefinitionUpdateManager",
"->",
"applyUpdates",
"(",
")",
";",
"}",
"}"
]
| Function to update field definitions for the additional SKU base fields.
This will not update the actual field but only additional information used
in custom code like field is configurable or not, indexable or not.
It will not do anything except updating the config. Be very careful when
using this.
@param string $field_code
Field code.
@param array $field
Field definition.
@throws \Exception
Throws exception if field doesn't exist in config. | [
"Function",
"to",
"update",
"field",
"definitions",
"for",
"the",
"additional",
"SKU",
"base",
"fields",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/SKUFieldsManager.php#L161-L204 | train |
acquia/commerce-manager | modules/acm_sku/src/SKUFieldsManager.php | SKUFieldsManager.getAllCustomFields | private function getAllCustomFields() {
$fields = [];
$this->moduleHandler->alter('acm_sku_base_field_additions', $fields);
foreach ($fields as $field_code => $field) {
$fields[$field_code] = $this->applyDefaults($field_code, $field);
}
return $fields;
} | php | private function getAllCustomFields() {
$fields = [];
$this->moduleHandler->alter('acm_sku_base_field_additions', $fields);
foreach ($fields as $field_code => $field) {
$fields[$field_code] = $this->applyDefaults($field_code, $field);
}
return $fields;
} | [
"private",
"function",
"getAllCustomFields",
"(",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"moduleHandler",
"->",
"alter",
"(",
"'acm_sku_base_field_additions'",
",",
"$",
"fields",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field_code",
"=>",
"$",
"field",
")",
"{",
"$",
"fields",
"[",
"$",
"field_code",
"]",
"=",
"$",
"this",
"->",
"applyDefaults",
"(",
"$",
"field_code",
",",
"$",
"field",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
]
| Get all fields defined in custom modules.
@return array
All fields defined in custom modules. | [
"Get",
"all",
"fields",
"defined",
"in",
"custom",
"modules",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/SKUFieldsManager.php#L222-L232 | train |
acquia/commerce-manager | modules/acm_sku/src/SKUFieldsManager.php | SKUFieldsManager.applyDefaults | private function applyDefaults($field_code, array $field) {
$defaults = $this->getDefaults();
if (empty($field['source'])) {
$field['source'] = $field_code;
}
// We will always have label, still we do a check to avoid errors.
if (empty($field['label'])) {
$field['label'] = $field_code;
}
// Add description if empty.
if (empty($field['description'])) {
$field['description'] = str_replace('[label]', $field['label'], $defaults['description']);
}
// Merge all other defaults.
$field += $defaults;
return $field;
} | php | private function applyDefaults($field_code, array $field) {
$defaults = $this->getDefaults();
if (empty($field['source'])) {
$field['source'] = $field_code;
}
// We will always have label, still we do a check to avoid errors.
if (empty($field['label'])) {
$field['label'] = $field_code;
}
// Add description if empty.
if (empty($field['description'])) {
$field['description'] = str_replace('[label]', $field['label'], $defaults['description']);
}
// Merge all other defaults.
$field += $defaults;
return $field;
} | [
"private",
"function",
"applyDefaults",
"(",
"$",
"field_code",
",",
"array",
"$",
"field",
")",
"{",
"$",
"defaults",
"=",
"$",
"this",
"->",
"getDefaults",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"field",
"[",
"'source'",
"]",
")",
")",
"{",
"$",
"field",
"[",
"'source'",
"]",
"=",
"$",
"field_code",
";",
"}",
"// We will always have label, still we do a check to avoid errors.",
"if",
"(",
"empty",
"(",
"$",
"field",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"field",
"[",
"'label'",
"]",
"=",
"$",
"field_code",
";",
"}",
"// Add description if empty.",
"if",
"(",
"empty",
"(",
"$",
"field",
"[",
"'description'",
"]",
")",
")",
"{",
"$",
"field",
"[",
"'description'",
"]",
"=",
"str_replace",
"(",
"'[label]'",
",",
"$",
"field",
"[",
"'label'",
"]",
",",
"$",
"defaults",
"[",
"'description'",
"]",
")",
";",
"}",
"// Merge all other defaults.",
"$",
"field",
"+=",
"$",
"defaults",
";",
"return",
"$",
"field",
";",
"}"
]
| Function to apply defaults and complete field definition.
@param string $field_code
Field code.
@param array $field
Field definition.
@return array
Field definition with all defaults applied. | [
"Function",
"to",
"apply",
"defaults",
"and",
"complete",
"field",
"definition",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/SKUFieldsManager.php#L245-L266 | train |
acquia/commerce-manager | modules/acm/src/Connector/APIWrapper.php | APIWrapper.silentRequest | public function silentRequest($method, array $params = []) {
$response = NULL;
if (!method_exists($this, $method)) {
throw new \InvalidArgumentException("Method {$method} doesn't exist.");
}
$this->turnRouteEventsOff();
try {
$response = call_user_func_array([$this, $method], $params);
}
catch (\Exception $e) {
$mesg = sprintf(
'Silent exception during %s request: (%d) - %s',
$method,
$e->getCode(),
$e->getMessage()
);
$this->logger->error($mesg);
}
$this->turnRouteEventsOn();
return $response;
} | php | public function silentRequest($method, array $params = []) {
$response = NULL;
if (!method_exists($this, $method)) {
throw new \InvalidArgumentException("Method {$method} doesn't exist.");
}
$this->turnRouteEventsOff();
try {
$response = call_user_func_array([$this, $method], $params);
}
catch (\Exception $e) {
$mesg = sprintf(
'Silent exception during %s request: (%d) - %s',
$method,
$e->getCode(),
$e->getMessage()
);
$this->logger->error($mesg);
}
$this->turnRouteEventsOn();
return $response;
} | [
"public",
"function",
"silentRequest",
"(",
"$",
"method",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"response",
"=",
"NULL",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Method {$method} doesn't exist.\"",
")",
";",
"}",
"$",
"this",
"->",
"turnRouteEventsOff",
"(",
")",
";",
"try",
"{",
"$",
"response",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"mesg",
"=",
"sprintf",
"(",
"'Silent exception during %s request: (%d) - %s'",
",",
"$",
"method",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"mesg",
")",
";",
"}",
"$",
"this",
"->",
"turnRouteEventsOn",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Perform a silent request.
Turns off route events and catches all exceptions.
@param string $method
The method name.
@param array $params
The method params.
@return mixed
The API request response.
@throws \Exception
Failed request exception. | [
"Perform",
"a",
"silent",
"request",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Connector/APIWrapper.php#L1001-L1027 | train |
acquia/commerce-manager | modules/acm/src/Connector/APIWrapper.php | APIWrapper.getProductPosition | public function getProductPosition($category_id) {
$endpoint = $this->apiVersion . "/agent/category/$category_id/position";
$doReq = function ($client, $opt) use ($endpoint) {
return ($client->get($endpoint, $opt));
};
$result = [];
try {
$result = $this->tryAgentRequest($doReq, 'productPosition', 'position');
}
catch (ConnectorException $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
return $result;
} | php | public function getProductPosition($category_id) {
$endpoint = $this->apiVersion . "/agent/category/$category_id/position";
$doReq = function ($client, $opt) use ($endpoint) {
return ($client->get($endpoint, $opt));
};
$result = [];
try {
$result = $this->tryAgentRequest($doReq, 'productPosition', 'position');
}
catch (ConnectorException $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
return $result;
} | [
"public",
"function",
"getProductPosition",
"(",
"$",
"category_id",
")",
"{",
"$",
"endpoint",
"=",
"$",
"this",
"->",
"apiVersion",
".",
"\"/agent/category/$category_id/position\"",
";",
"$",
"doReq",
"=",
"function",
"(",
"$",
"client",
",",
"$",
"opt",
")",
"use",
"(",
"$",
"endpoint",
")",
"{",
"return",
"(",
"$",
"client",
"->",
"get",
"(",
"$",
"endpoint",
",",
"$",
"opt",
")",
")",
";",
"}",
";",
"$",
"result",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"tryAgentRequest",
"(",
"$",
"doReq",
",",
"'productPosition'",
",",
"'position'",
")",
";",
"}",
"catch",
"(",
"ConnectorException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Get position of the products in a category.
@param int $category_id
The category id.
@return array
All products with the positions in the given category.
@throws \Exception | [
"Get",
"position",
"of",
"the",
"products",
"in",
"a",
"category",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Connector/APIWrapper.php#L1040-L1057 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ObjectContainerTrait.php | ObjectContainerTrait.setObjId | public function setObjId($objId)
{
if (!is_scalar($objId)) {
throw new InvalidArgumentException(sprintf(
'Object ID must be a string or numerical value, received %s.',
(is_object($objId) ? get_class($objId) : gettype($objId))
));
}
$this->objId = $objId;
return $this;
} | php | public function setObjId($objId)
{
if (!is_scalar($objId)) {
throw new InvalidArgumentException(sprintf(
'Object ID must be a string or numerical value, received %s.',
(is_object($objId) ? get_class($objId) : gettype($objId))
));
}
$this->objId = $objId;
return $this;
} | [
"public",
"function",
"setObjId",
"(",
"$",
"objId",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"objId",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Object ID must be a string or numerical value, received %s.'",
",",
"(",
"is_object",
"(",
"$",
"objId",
")",
"?",
"get_class",
"(",
"$",
"objId",
")",
":",
"gettype",
"(",
"$",
"objId",
")",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"objId",
"=",
"$",
"objId",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the object ID.
@param string|numeric $objId The object ID to load.
@throws InvalidArgumentException If provided argument is not of type 'scalar'.
@return ObjectContainerInterface Chainable | [
"Set",
"the",
"object",
"ID",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ObjectContainerTrait.php#L108-L120 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ObjectContainerTrait.php | ObjectContainerTrait.obj | public function obj()
{
if ($this->obj === null) {
$this->obj = $this->createOrLoadObj();
if ($this->obj instanceof ModelInterface) {
$this->objId = $this->obj->id();
} else {
$this->objId = null;
}
}
return $this->obj;
} | php | public function obj()
{
if ($this->obj === null) {
$this->obj = $this->createOrLoadObj();
if ($this->obj instanceof ModelInterface) {
$this->objId = $this->obj->id();
} else {
$this->objId = null;
}
}
return $this->obj;
} | [
"public",
"function",
"obj",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"obj",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"obj",
"=",
"$",
"this",
"->",
"createOrLoadObj",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"obj",
"instanceof",
"ModelInterface",
")",
"{",
"$",
"this",
"->",
"objId",
"=",
"$",
"this",
"->",
"obj",
"->",
"id",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"objId",
"=",
"null",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"obj",
";",
"}"
]
| Retrieve the object.
@return ModelInterface | [
"Retrieve",
"the",
"object",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ObjectContainerTrait.php#L199-L212 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Ui/ObjectContainerTrait.php | ObjectContainerTrait.createOrLoadObj | protected function createOrLoadObj()
{
if ($this->objId()) {
return $this->loadObj();
} elseif (!empty($_GET['clone_id'])) {
return $this->cloneObj();
} elseif (!empty($_GET['blueprint_id'])) {
return $this->createObjFromBluePrint();
} else {
return $this->createObj();
}
} | php | protected function createOrLoadObj()
{
if ($this->objId()) {
return $this->loadObj();
} elseif (!empty($_GET['clone_id'])) {
return $this->cloneObj();
} elseif (!empty($_GET['blueprint_id'])) {
return $this->createObjFromBluePrint();
} else {
return $this->createObj();
}
} | [
"protected",
"function",
"createOrLoadObj",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"objId",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loadObj",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'clone_id'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cloneObj",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'blueprint_id'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createObjFromBluePrint",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"createObj",
"(",
")",
";",
"}",
"}"
]
| Create or load the object.
@return ModelInterface | [
"Create",
"or",
"load",
"the",
"object",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/ObjectContainerTrait.php#L219-L230 | train |
acquia/commerce-manager | modules/acm/src/Element/AcmEmailUpdate.php | AcmEmailUpdate.processEmailUpdate | public static function processEmailUpdate(&$element, FormStateInterface $form_state, &$complete_form) {
$element['email'] = [
'#type' => 'email',
'#title' => isset($element['#title']) ? $element['#title'] : '',
'#value' => isset($element['#value']['email']) ? $element['#value']['email'] : NULL,
'#required' => $element['#required'],
'#error_no_message' => TRUE,
];
$element['password'] = [
'#type' => 'password',
'#title' => t('Password'),
'#value' => isset($element['#value']['password']) ? $element['#value']['password'] : NULL,
'#required' => $element['#required'],
'#error_no_message' => TRUE,
];
$element['#element_validate'] = [[get_called_class(), 'validateEmailUpdate']];
$element['#tree'] = TRUE;
return $element;
} | php | public static function processEmailUpdate(&$element, FormStateInterface $form_state, &$complete_form) {
$element['email'] = [
'#type' => 'email',
'#title' => isset($element['#title']) ? $element['#title'] : '',
'#value' => isset($element['#value']['email']) ? $element['#value']['email'] : NULL,
'#required' => $element['#required'],
'#error_no_message' => TRUE,
];
$element['password'] = [
'#type' => 'password',
'#title' => t('Password'),
'#value' => isset($element['#value']['password']) ? $element['#value']['password'] : NULL,
'#required' => $element['#required'],
'#error_no_message' => TRUE,
];
$element['#element_validate'] = [[get_called_class(), 'validateEmailUpdate']];
$element['#tree'] = TRUE;
return $element;
} | [
"public",
"static",
"function",
"processEmailUpdate",
"(",
"&",
"$",
"element",
",",
"FormStateInterface",
"$",
"form_state",
",",
"&",
"$",
"complete_form",
")",
"{",
"$",
"element",
"[",
"'email'",
"]",
"=",
"[",
"'#type'",
"=>",
"'email'",
",",
"'#title'",
"=>",
"isset",
"(",
"$",
"element",
"[",
"'#title'",
"]",
")",
"?",
"$",
"element",
"[",
"'#title'",
"]",
":",
"''",
",",
"'#value'",
"=>",
"isset",
"(",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'email'",
"]",
")",
"?",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'email'",
"]",
":",
"NULL",
",",
"'#required'",
"=>",
"$",
"element",
"[",
"'#required'",
"]",
",",
"'#error_no_message'",
"=>",
"TRUE",
",",
"]",
";",
"$",
"element",
"[",
"'password'",
"]",
"=",
"[",
"'#type'",
"=>",
"'password'",
",",
"'#title'",
"=>",
"t",
"(",
"'Password'",
")",
",",
"'#value'",
"=>",
"isset",
"(",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'password'",
"]",
")",
"?",
"$",
"element",
"[",
"'#value'",
"]",
"[",
"'password'",
"]",
":",
"NULL",
",",
"'#required'",
"=>",
"$",
"element",
"[",
"'#required'",
"]",
",",
"'#error_no_message'",
"=>",
"TRUE",
",",
"]",
";",
"$",
"element",
"[",
"'#element_validate'",
"]",
"=",
"[",
"[",
"get_called_class",
"(",
")",
",",
"'validateEmailUpdate'",
"]",
"]",
";",
"$",
"element",
"[",
"'#tree'",
"]",
"=",
"TRUE",
";",
"return",
"$",
"element",
";",
"}"
]
| Expand an acm_email_update field into two text boxes. | [
"Expand",
"an",
"acm_email_update",
"field",
"into",
"two",
"text",
"boxes",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Element/AcmEmailUpdate.php#L67-L86 | train |
locomotivemtl/charcoal-admin | src/Charcoal/Admin/Action/Object/RevertRevisionAction.php | RevertRevisionAction.setRevNum | protected function setRevNum($revNum)
{
if (!is_numeric($revNum)) {
throw new InvalidArgumentException(sprintf(
'Revision must be an integer, received %s.',
(is_object($revNum) ? get_class($revNum) : gettype($revNum))
));
}
$this->revNum = (int)$revNum;
return $this;
} | php | protected function setRevNum($revNum)
{
if (!is_numeric($revNum)) {
throw new InvalidArgumentException(sprintf(
'Revision must be an integer, received %s.',
(is_object($revNum) ? get_class($revNum) : gettype($revNum))
));
}
$this->revNum = (int)$revNum;
return $this;
} | [
"protected",
"function",
"setRevNum",
"(",
"$",
"revNum",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"revNum",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Revision must be an integer, received %s.'",
",",
"(",
"is_object",
"(",
"$",
"revNum",
")",
"?",
"get_class",
"(",
"$",
"revNum",
")",
":",
"gettype",
"(",
"$",
"revNum",
")",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"revNum",
"=",
"(",
"int",
")",
"$",
"revNum",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the revision number to restore.
@param integer $revNum The revision number to load.
@throws InvalidArgumentException If the given revision is invalid.
@return ObjectContainerInterface Chainable | [
"Set",
"the",
"revision",
"number",
"to",
"restore",
"."
]
| d7394e62ab8b374bcdd1dbeaedec0f6c35624571 | https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Object/RevertRevisionAction.php#L69-L81 | train |
acquia/commerce-manager | modules/acm/src/ACMAddressFormatter.php | ACMAddressFormatter.render | public function render($address) {
$element = [
'#prefix' => '<p class="address" translate="no">',
'#suffix' => '</p>',
'#post_render' => [
[get_class($this), 'postRender'],
],
'#cache' => [
'contexts' => [
'languages:' . LanguageInterface::TYPE_INTERFACE,
],
],
] + $this->viewElement($address, 'en');
return render($element);
} | php | public function render($address) {
$element = [
'#prefix' => '<p class="address" translate="no">',
'#suffix' => '</p>',
'#post_render' => [
[get_class($this), 'postRender'],
],
'#cache' => [
'contexts' => [
'languages:' . LanguageInterface::TYPE_INTERFACE,
],
],
] + $this->viewElement($address, 'en');
return render($element);
} | [
"public",
"function",
"render",
"(",
"$",
"address",
")",
"{",
"$",
"element",
"=",
"[",
"'#prefix'",
"=>",
"'<p class=\"address\" translate=\"no\">'",
",",
"'#suffix'",
"=>",
"'</p>'",
",",
"'#post_render'",
"=>",
"[",
"[",
"get_class",
"(",
"$",
"this",
")",
",",
"'postRender'",
"]",
",",
"]",
",",
"'#cache'",
"=>",
"[",
"'contexts'",
"=>",
"[",
"'languages:'",
".",
"LanguageInterface",
"::",
"TYPE_INTERFACE",
",",
"]",
",",
"]",
",",
"]",
"+",
"$",
"this",
"->",
"viewElement",
"(",
"$",
"address",
",",
"'en'",
")",
";",
"return",
"render",
"(",
"$",
"element",
")",
";",
"}"
]
| Render address.
@param object $address
The address.
@return mixed|null
A renderable array. | [
"Render",
"address",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/ACMAddressFormatter.php#L26-L41 | train |
acquia/commerce-manager | modules/acm/src/ACMAddressFormatter.php | ACMAddressFormatter.viewElement | protected function viewElement($address, $langcode) {
$country_code = $address->country_id;
$country_repository = \Drupal::service('address.country_repository');
$countries = $country_repository->getList();
$address_format_repository = \Drupal::service('address.address_format_repository');
$address_format = $address_format_repository->get($country_code);
$values = $this->getValues($address, $country_code, $address_format);
$element = [];
$element['address_format'] = [
'#type' => 'value',
'#value' => $address_format,
];
// TODO get the locale from the i18n helper.
$element['locale'] = [
'#type' => 'value',
'#value' => 'en',
];
$element['country_code'] = [
'#type' => 'value',
'#value' => $country_code,
];
$element['country'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => ['class' => ['country']],
'#value' => Html::escape($countries[$country_code]),
'#placeholder' => '%country',
];
foreach ($address_format->getUsedFields() as $field) {
$property = FieldHelper::getPropertyName($field);
$class = str_replace('_', '-', $property);
$element[$property] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => ['class' => [$class]],
'#value' => $values[$field],
'#placeholder' => '%' . $field,
];
}
$element['title'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => ['class' => ['title']],
'#value' => $values['title'],
'#placeholder' => '%title',
];
return $element;
} | php | protected function viewElement($address, $langcode) {
$country_code = $address->country_id;
$country_repository = \Drupal::service('address.country_repository');
$countries = $country_repository->getList();
$address_format_repository = \Drupal::service('address.address_format_repository');
$address_format = $address_format_repository->get($country_code);
$values = $this->getValues($address, $country_code, $address_format);
$element = [];
$element['address_format'] = [
'#type' => 'value',
'#value' => $address_format,
];
// TODO get the locale from the i18n helper.
$element['locale'] = [
'#type' => 'value',
'#value' => 'en',
];
$element['country_code'] = [
'#type' => 'value',
'#value' => $country_code,
];
$element['country'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => ['class' => ['country']],
'#value' => Html::escape($countries[$country_code]),
'#placeholder' => '%country',
];
foreach ($address_format->getUsedFields() as $field) {
$property = FieldHelper::getPropertyName($field);
$class = str_replace('_', '-', $property);
$element[$property] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => ['class' => [$class]],
'#value' => $values[$field],
'#placeholder' => '%' . $field,
];
}
$element['title'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => ['class' => ['title']],
'#value' => $values['title'],
'#placeholder' => '%title',
];
return $element;
} | [
"protected",
"function",
"viewElement",
"(",
"$",
"address",
",",
"$",
"langcode",
")",
"{",
"$",
"country_code",
"=",
"$",
"address",
"->",
"country_id",
";",
"$",
"country_repository",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'address.country_repository'",
")",
";",
"$",
"countries",
"=",
"$",
"country_repository",
"->",
"getList",
"(",
")",
";",
"$",
"address_format_repository",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'address.address_format_repository'",
")",
";",
"$",
"address_format",
"=",
"$",
"address_format_repository",
"->",
"get",
"(",
"$",
"country_code",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getValues",
"(",
"$",
"address",
",",
"$",
"country_code",
",",
"$",
"address_format",
")",
";",
"$",
"element",
"=",
"[",
"]",
";",
"$",
"element",
"[",
"'address_format'",
"]",
"=",
"[",
"'#type'",
"=>",
"'value'",
",",
"'#value'",
"=>",
"$",
"address_format",
",",
"]",
";",
"// TODO get the locale from the i18n helper.",
"$",
"element",
"[",
"'locale'",
"]",
"=",
"[",
"'#type'",
"=>",
"'value'",
",",
"'#value'",
"=>",
"'en'",
",",
"]",
";",
"$",
"element",
"[",
"'country_code'",
"]",
"=",
"[",
"'#type'",
"=>",
"'value'",
",",
"'#value'",
"=>",
"$",
"country_code",
",",
"]",
";",
"$",
"element",
"[",
"'country'",
"]",
"=",
"[",
"'#type'",
"=>",
"'html_tag'",
",",
"'#tag'",
"=>",
"'span'",
",",
"'#attributes'",
"=>",
"[",
"'class'",
"=>",
"[",
"'country'",
"]",
"]",
",",
"'#value'",
"=>",
"Html",
"::",
"escape",
"(",
"$",
"countries",
"[",
"$",
"country_code",
"]",
")",
",",
"'#placeholder'",
"=>",
"'%country'",
",",
"]",
";",
"foreach",
"(",
"$",
"address_format",
"->",
"getUsedFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"property",
"=",
"FieldHelper",
"::",
"getPropertyName",
"(",
"$",
"field",
")",
";",
"$",
"class",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"property",
")",
";",
"$",
"element",
"[",
"$",
"property",
"]",
"=",
"[",
"'#type'",
"=>",
"'html_tag'",
",",
"'#tag'",
"=>",
"'span'",
",",
"'#attributes'",
"=>",
"[",
"'class'",
"=>",
"[",
"$",
"class",
"]",
"]",
",",
"'#value'",
"=>",
"$",
"values",
"[",
"$",
"field",
"]",
",",
"'#placeholder'",
"=>",
"'%'",
".",
"$",
"field",
",",
"]",
";",
"}",
"$",
"element",
"[",
"'title'",
"]",
"=",
"[",
"'#type'",
"=>",
"'html_tag'",
",",
"'#tag'",
"=>",
"'span'",
",",
"'#attributes'",
"=>",
"[",
"'class'",
"=>",
"[",
"'title'",
"]",
"]",
",",
"'#value'",
"=>",
"$",
"values",
"[",
"'title'",
"]",
",",
"'#placeholder'",
"=>",
"'%title'",
",",
"]",
";",
"return",
"$",
"element",
";",
"}"
]
| Builds a renderable array for a single address item.
@param object $address
The address.
@param string $langcode
The language that should be used to render the field.
@return array
A renderable array. | [
"Builds",
"a",
"renderable",
"array",
"for",
"a",
"single",
"address",
"item",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/ACMAddressFormatter.php#L54-L105 | train |
acquia/commerce-manager | modules/acm/src/ACMAddressFormatter.php | ACMAddressFormatter.getValues | protected function getValues($address, $country_code, AddressFormat $address_format) {
$values = [];
$values['title'] = isset($address->title) ? $address->title : '';
$values['givenName'] = isset($address->firstname) ? $address->firstname : '';
$values['familyName'] = isset($address->lastname) ? $address->lastname : '';
$values['organization'] = isset($address->organization) ? $address->organization : '';
$values['addressLine1'] = isset($address->street) ? $address->street : '';
$values['addressLine2'] = isset($address->street2) ? $address->street2 : '';
$values['postalCode'] = isset($address->postcode) ? $address->postcode : '';
$values['administrativeArea'] = isset($address->region) ? $address->region : '';
$values['locality'] = isset($address->city) ? $address->city : '';
$values['dependentLocality'] = isset($address->dependent_locality) ? $address->dependent_locality : '';
$original_values = [];
$subdivision_fields = $address_format->getUsedSubdivisionFields();
$parents = [];
foreach ($subdivision_fields as $index => $field) {
if (empty($values[$field])) {
// This level is empty, so there can be no sublevels.
break;
}
$parents[] = $index ? $original_values[$subdivision_fields[$index - 1]] : $address->country_id;
$subdivision_repository = \Drupal::service('address.subdivision_repository');
$subdivision = $subdivision_repository->get($values[$field], $parents);
if (!$subdivision) {
break;
}
// Remember the original value so that it can be used for $parents.
$original_values[$field] = $values[$field];
// Replace the value with the expected code.
$use_local_name = Locale::match('en', $subdivision->getLocale());
$values[$field] = $use_local_name ? $subdivision->getLocalCode() : $subdivision->getCode();
if (!$subdivision->hasChildren()) {
// The current subdivision has no children, stop.
break;
}
}
return $values;
} | php | protected function getValues($address, $country_code, AddressFormat $address_format) {
$values = [];
$values['title'] = isset($address->title) ? $address->title : '';
$values['givenName'] = isset($address->firstname) ? $address->firstname : '';
$values['familyName'] = isset($address->lastname) ? $address->lastname : '';
$values['organization'] = isset($address->organization) ? $address->organization : '';
$values['addressLine1'] = isset($address->street) ? $address->street : '';
$values['addressLine2'] = isset($address->street2) ? $address->street2 : '';
$values['postalCode'] = isset($address->postcode) ? $address->postcode : '';
$values['administrativeArea'] = isset($address->region) ? $address->region : '';
$values['locality'] = isset($address->city) ? $address->city : '';
$values['dependentLocality'] = isset($address->dependent_locality) ? $address->dependent_locality : '';
$original_values = [];
$subdivision_fields = $address_format->getUsedSubdivisionFields();
$parents = [];
foreach ($subdivision_fields as $index => $field) {
if (empty($values[$field])) {
// This level is empty, so there can be no sublevels.
break;
}
$parents[] = $index ? $original_values[$subdivision_fields[$index - 1]] : $address->country_id;
$subdivision_repository = \Drupal::service('address.subdivision_repository');
$subdivision = $subdivision_repository->get($values[$field], $parents);
if (!$subdivision) {
break;
}
// Remember the original value so that it can be used for $parents.
$original_values[$field] = $values[$field];
// Replace the value with the expected code.
$use_local_name = Locale::match('en', $subdivision->getLocale());
$values[$field] = $use_local_name ? $subdivision->getLocalCode() : $subdivision->getCode();
if (!$subdivision->hasChildren()) {
// The current subdivision has no children, stop.
break;
}
}
return $values;
} | [
"protected",
"function",
"getValues",
"(",
"$",
"address",
",",
"$",
"country_code",
",",
"AddressFormat",
"$",
"address_format",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"values",
"[",
"'title'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"title",
")",
"?",
"$",
"address",
"->",
"title",
":",
"''",
";",
"$",
"values",
"[",
"'givenName'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"firstname",
")",
"?",
"$",
"address",
"->",
"firstname",
":",
"''",
";",
"$",
"values",
"[",
"'familyName'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"lastname",
")",
"?",
"$",
"address",
"->",
"lastname",
":",
"''",
";",
"$",
"values",
"[",
"'organization'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"organization",
")",
"?",
"$",
"address",
"->",
"organization",
":",
"''",
";",
"$",
"values",
"[",
"'addressLine1'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"street",
")",
"?",
"$",
"address",
"->",
"street",
":",
"''",
";",
"$",
"values",
"[",
"'addressLine2'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"street2",
")",
"?",
"$",
"address",
"->",
"street2",
":",
"''",
";",
"$",
"values",
"[",
"'postalCode'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"postcode",
")",
"?",
"$",
"address",
"->",
"postcode",
":",
"''",
";",
"$",
"values",
"[",
"'administrativeArea'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"region",
")",
"?",
"$",
"address",
"->",
"region",
":",
"''",
";",
"$",
"values",
"[",
"'locality'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"city",
")",
"?",
"$",
"address",
"->",
"city",
":",
"''",
";",
"$",
"values",
"[",
"'dependentLocality'",
"]",
"=",
"isset",
"(",
"$",
"address",
"->",
"dependent_locality",
")",
"?",
"$",
"address",
"->",
"dependent_locality",
":",
"''",
";",
"$",
"original_values",
"=",
"[",
"]",
";",
"$",
"subdivision_fields",
"=",
"$",
"address_format",
"->",
"getUsedSubdivisionFields",
"(",
")",
";",
"$",
"parents",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"subdivision_fields",
"as",
"$",
"index",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
"[",
"$",
"field",
"]",
")",
")",
"{",
"// This level is empty, so there can be no sublevels.",
"break",
";",
"}",
"$",
"parents",
"[",
"]",
"=",
"$",
"index",
"?",
"$",
"original_values",
"[",
"$",
"subdivision_fields",
"[",
"$",
"index",
"-",
"1",
"]",
"]",
":",
"$",
"address",
"->",
"country_id",
";",
"$",
"subdivision_repository",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'address.subdivision_repository'",
")",
";",
"$",
"subdivision",
"=",
"$",
"subdivision_repository",
"->",
"get",
"(",
"$",
"values",
"[",
"$",
"field",
"]",
",",
"$",
"parents",
")",
";",
"if",
"(",
"!",
"$",
"subdivision",
")",
"{",
"break",
";",
"}",
"// Remember the original value so that it can be used for $parents.",
"$",
"original_values",
"[",
"$",
"field",
"]",
"=",
"$",
"values",
"[",
"$",
"field",
"]",
";",
"// Replace the value with the expected code.",
"$",
"use_local_name",
"=",
"Locale",
"::",
"match",
"(",
"'en'",
",",
"$",
"subdivision",
"->",
"getLocale",
"(",
")",
")",
";",
"$",
"values",
"[",
"$",
"field",
"]",
"=",
"$",
"use_local_name",
"?",
"$",
"subdivision",
"->",
"getLocalCode",
"(",
")",
":",
"$",
"subdivision",
"->",
"getCode",
"(",
")",
";",
"if",
"(",
"!",
"$",
"subdivision",
"->",
"hasChildren",
"(",
")",
")",
"{",
"// The current subdivision has no children, stop.",
"break",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
]
| Gets the address values used for rendering.
@param object $address
The address.
@param string $country_code
The country code.
@param \CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format
The address format.
@return array
The values, keyed by address field. | [
"Gets",
"the",
"address",
"values",
"used",
"for",
"rendering",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/ACMAddressFormatter.php#L120-L160 | train |
acquia/commerce-manager | modules/acm/src/ACMAddressFormatter.php | ACMAddressFormatter.postRender | public static function postRender($content, array $element) {
/** @var \CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format */
$address_format = $element['address_format']['#value'];
$locale = $element['locale']['#value'];
// Add the country to the bottom or the top of the format string,
// depending on whether the format is minor-to-major or major-to-minor.
if (Locale::match($address_format->getLocale(), $locale)) {
$format_string = '%country' . "\n" . $address_format->getLocalFormat();
}
else {
$format_string = $address_format->getFormat() . "\n" . '%country';
}
// Add the title (prefix) into the format string before the first name.
// Note: This feels like the wrong place to add address formatting.
// (notwithstanding %country above).
// You may inspect the constructor of
// vendor/commerceguys/addressing/src/AddressFormat/AddressFormat.php
// And figure out how to extend the class that sets $definition['format']
// and/or $definition['local_format'].
// But for now for speed and convenience we inject the %title here.
// (With some consideration for different locale naming possibilities)
if (strpos($format_string, '%givenName %familyName') !== FALSE) {
$format_string = str_replace('%givenName %familyName',
'%title %givenName %familyName', $format_string);
}
elseif (strpos($format_string, '%familyName %givenName') !== FALSE) {
$format_string = str_replace('%familyName %givenName',
'%title %familyName %givenName', $format_string);
}
elseif (strpos($format_string, '%familyName') !== FALSE) {
$format_string = str_replace('%familyName',
'%title %familyName', $format_string);
}
elseif (strpos($format_string, '%givenName') !== FALSE) {
$format_string = str_replace('%givenName',
'%title %givenName', $format_string);
}
$replacements = [];
foreach (Element::getVisibleChildren($element) as $key) {
$child = $element[$key];
if (isset($child['#placeholder'])) {
$replacements[$child['#placeholder']] = $child['#value'] ? $child['#markup'] : '';
}
}
$content = self::replacePlaceholders($format_string, $replacements);
$content = nl2br($content, FALSE);
return $content;
} | php | public static function postRender($content, array $element) {
/** @var \CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format */
$address_format = $element['address_format']['#value'];
$locale = $element['locale']['#value'];
// Add the country to the bottom or the top of the format string,
// depending on whether the format is minor-to-major or major-to-minor.
if (Locale::match($address_format->getLocale(), $locale)) {
$format_string = '%country' . "\n" . $address_format->getLocalFormat();
}
else {
$format_string = $address_format->getFormat() . "\n" . '%country';
}
// Add the title (prefix) into the format string before the first name.
// Note: This feels like the wrong place to add address formatting.
// (notwithstanding %country above).
// You may inspect the constructor of
// vendor/commerceguys/addressing/src/AddressFormat/AddressFormat.php
// And figure out how to extend the class that sets $definition['format']
// and/or $definition['local_format'].
// But for now for speed and convenience we inject the %title here.
// (With some consideration for different locale naming possibilities)
if (strpos($format_string, '%givenName %familyName') !== FALSE) {
$format_string = str_replace('%givenName %familyName',
'%title %givenName %familyName', $format_string);
}
elseif (strpos($format_string, '%familyName %givenName') !== FALSE) {
$format_string = str_replace('%familyName %givenName',
'%title %familyName %givenName', $format_string);
}
elseif (strpos($format_string, '%familyName') !== FALSE) {
$format_string = str_replace('%familyName',
'%title %familyName', $format_string);
}
elseif (strpos($format_string, '%givenName') !== FALSE) {
$format_string = str_replace('%givenName',
'%title %givenName', $format_string);
}
$replacements = [];
foreach (Element::getVisibleChildren($element) as $key) {
$child = $element[$key];
if (isset($child['#placeholder'])) {
$replacements[$child['#placeholder']] = $child['#value'] ? $child['#markup'] : '';
}
}
$content = self::replacePlaceholders($format_string, $replacements);
$content = nl2br($content, FALSE);
return $content;
} | [
"public",
"static",
"function",
"postRender",
"(",
"$",
"content",
",",
"array",
"$",
"element",
")",
"{",
"/** @var \\CommerceGuys\\Addressing\\AddressFormat\\AddressFormat $address_format */",
"$",
"address_format",
"=",
"$",
"element",
"[",
"'address_format'",
"]",
"[",
"'#value'",
"]",
";",
"$",
"locale",
"=",
"$",
"element",
"[",
"'locale'",
"]",
"[",
"'#value'",
"]",
";",
"// Add the country to the bottom or the top of the format string,",
"// depending on whether the format is minor-to-major or major-to-minor.",
"if",
"(",
"Locale",
"::",
"match",
"(",
"$",
"address_format",
"->",
"getLocale",
"(",
")",
",",
"$",
"locale",
")",
")",
"{",
"$",
"format_string",
"=",
"'%country'",
".",
"\"\\n\"",
".",
"$",
"address_format",
"->",
"getLocalFormat",
"(",
")",
";",
"}",
"else",
"{",
"$",
"format_string",
"=",
"$",
"address_format",
"->",
"getFormat",
"(",
")",
".",
"\"\\n\"",
".",
"'%country'",
";",
"}",
"// Add the title (prefix) into the format string before the first name.",
"// Note: This feels like the wrong place to add address formatting.",
"// (notwithstanding %country above).",
"// You may inspect the constructor of",
"// vendor/commerceguys/addressing/src/AddressFormat/AddressFormat.php",
"// And figure out how to extend the class that sets $definition['format']",
"// and/or $definition['local_format'].",
"// But for now for speed and convenience we inject the %title here.",
"// (With some consideration for different locale naming possibilities)",
"if",
"(",
"strpos",
"(",
"$",
"format_string",
",",
"'%givenName %familyName'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"format_string",
"=",
"str_replace",
"(",
"'%givenName %familyName'",
",",
"'%title %givenName %familyName'",
",",
"$",
"format_string",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"format_string",
",",
"'%familyName %givenName'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"format_string",
"=",
"str_replace",
"(",
"'%familyName %givenName'",
",",
"'%title %familyName %givenName'",
",",
"$",
"format_string",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"format_string",
",",
"'%familyName'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"format_string",
"=",
"str_replace",
"(",
"'%familyName'",
",",
"'%title %familyName'",
",",
"$",
"format_string",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"format_string",
",",
"'%givenName'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"format_string",
"=",
"str_replace",
"(",
"'%givenName'",
",",
"'%title %givenName'",
",",
"$",
"format_string",
")",
";",
"}",
"$",
"replacements",
"=",
"[",
"]",
";",
"foreach",
"(",
"Element",
"::",
"getVisibleChildren",
"(",
"$",
"element",
")",
"as",
"$",
"key",
")",
"{",
"$",
"child",
"=",
"$",
"element",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"child",
"[",
"'#placeholder'",
"]",
")",
")",
"{",
"$",
"replacements",
"[",
"$",
"child",
"[",
"'#placeholder'",
"]",
"]",
"=",
"$",
"child",
"[",
"'#value'",
"]",
"?",
"$",
"child",
"[",
"'#markup'",
"]",
":",
"''",
";",
"}",
"}",
"$",
"content",
"=",
"self",
"::",
"replacePlaceholders",
"(",
"$",
"format_string",
",",
"$",
"replacements",
")",
";",
"$",
"content",
"=",
"nl2br",
"(",
"$",
"content",
",",
"FALSE",
")",
";",
"return",
"$",
"content",
";",
"}"
]
| Inserts the rendered elements into the format string.
Only elements whose placeholders match words in the format string are
added. So if you want to display extra elements, set the
element's #placeholder to '%thing'
and ensure somehow that '%thing' is in format_string.
@param string $content
The rendered element.
@param array $element
An associative array containing the properties and children of the
element.
@return string
The new rendered element. | [
"Inserts",
"the",
"rendered",
"elements",
"into",
"the",
"format",
"string",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/ACMAddressFormatter.php#L179-L229 | train |
acquia/commerce-manager | modules/acm/src/ACMAddressFormatter.php | ACMAddressFormatter.replacePlaceholders | public static function replacePlaceholders($string, array $replacements) {
// Make sure the replacements don't have any unneeded newlines.
$replacements = array_map('trim', $replacements);
$string = strtr($string, $replacements);
// Remove noise caused by empty placeholders.
$lines = explode("\n", $string);
foreach ($lines as $index => $line) {
// Remove leading punctuation, excess whitespace.
$line = trim(preg_replace('/^[-,]+/', '', $line, 1));
$line = preg_replace('/\s\s+/', ' ', $line);
$lines[$index] = $line;
}
// Remove empty lines.
$lines = array_filter($lines);
return implode("\n", $lines);
} | php | public static function replacePlaceholders($string, array $replacements) {
// Make sure the replacements don't have any unneeded newlines.
$replacements = array_map('trim', $replacements);
$string = strtr($string, $replacements);
// Remove noise caused by empty placeholders.
$lines = explode("\n", $string);
foreach ($lines as $index => $line) {
// Remove leading punctuation, excess whitespace.
$line = trim(preg_replace('/^[-,]+/', '', $line, 1));
$line = preg_replace('/\s\s+/', ' ', $line);
$lines[$index] = $line;
}
// Remove empty lines.
$lines = array_filter($lines);
return implode("\n", $lines);
} | [
"public",
"static",
"function",
"replacePlaceholders",
"(",
"$",
"string",
",",
"array",
"$",
"replacements",
")",
"{",
"// Make sure the replacements don't have any unneeded newlines.",
"$",
"replacements",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"replacements",
")",
";",
"$",
"string",
"=",
"strtr",
"(",
"$",
"string",
",",
"$",
"replacements",
")",
";",
"// Remove noise caused by empty placeholders.",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"string",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"index",
"=>",
"$",
"line",
")",
"{",
"// Remove leading punctuation, excess whitespace.",
"$",
"line",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/^[-,]+/'",
",",
"''",
",",
"$",
"line",
",",
"1",
")",
")",
";",
"$",
"line",
"=",
"preg_replace",
"(",
"'/\\s\\s+/'",
",",
"' '",
",",
"$",
"line",
")",
";",
"$",
"lines",
"[",
"$",
"index",
"]",
"=",
"$",
"line",
";",
"}",
"// Remove empty lines.",
"$",
"lines",
"=",
"array_filter",
"(",
"$",
"lines",
")",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
]
| Replaces placeholders in the given string.
@param string $string
The string containing the placeholders.
@param array $replacements
An array of replacements keyed by their placeholders.
@return string
The processed string. | [
"Replaces",
"placeholders",
"in",
"the",
"given",
"string",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/ACMAddressFormatter.php#L242-L258 | train |
acquia/commerce-manager | modules/acm/src/User/AccessTokenTrait.php | AccessTokenTrait.getAccessToken | protected function getAccessToken() {
$cookies = $_COOKIE;
if (isset(\Drupal::request()->cookies)) {
$cookies = \Drupal::request()->cookies->all();
}
$cookie_name = 'Drupal_visitor_' . $this->accessTokenCookie;
if (isset($cookies[$cookie_name])) {
return $cookies[$cookie_name];
}
return NULL;
} | php | protected function getAccessToken() {
$cookies = $_COOKIE;
if (isset(\Drupal::request()->cookies)) {
$cookies = \Drupal::request()->cookies->all();
}
$cookie_name = 'Drupal_visitor_' . $this->accessTokenCookie;
if (isset($cookies[$cookie_name])) {
return $cookies[$cookie_name];
}
return NULL;
} | [
"protected",
"function",
"getAccessToken",
"(",
")",
"{",
"$",
"cookies",
"=",
"$",
"_COOKIE",
";",
"if",
"(",
"isset",
"(",
"\\",
"Drupal",
"::",
"request",
"(",
")",
"->",
"cookies",
")",
")",
"{",
"$",
"cookies",
"=",
"\\",
"Drupal",
"::",
"request",
"(",
")",
"->",
"cookies",
"->",
"all",
"(",
")",
";",
"}",
"$",
"cookie_name",
"=",
"'Drupal_visitor_'",
".",
"$",
"this",
"->",
"accessTokenCookie",
";",
"if",
"(",
"isset",
"(",
"$",
"cookies",
"[",
"$",
"cookie_name",
"]",
")",
")",
"{",
"return",
"$",
"cookies",
"[",
"$",
"cookie_name",
"]",
";",
"}",
"return",
"NULL",
";",
"}"
]
| Gets a user access token. | [
"Gets",
"a",
"user",
"access",
"token",
"."
]
| e6c3a5fb9166d6c447725339ac4e0ae341c06d50 | https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/User/AccessTokenTrait.php#L20-L34 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.