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
dmt-software/jms-soap-serializer
src/SoapSerializationVisitorFactory.php
SoapSerializationVisitorFactory.getSoapNamespace
protected function getSoapNamespace(): string { if (!array_key_exists($this->soapVersion, static::SOAP_NAMESPACES)) { throw new InvalidArgumentException('Unsupported SOAP version'); } return static::SOAP_NAMESPACES[$this->soapVersion]; }
php
protected function getSoapNamespace(): string { if (!array_key_exists($this->soapVersion, static::SOAP_NAMESPACES)) { throw new InvalidArgumentException('Unsupported SOAP version'); } return static::SOAP_NAMESPACES[$this->soapVersion]; }
[ "protected", "function", "getSoapNamespace", "(", ")", ":", "string", "{", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "soapVersion", ",", "static", "::", "SOAP_NAMESPACES", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Unsupported SOAP version'", ")", ";", "}", "return", "static", "::", "SOAP_NAMESPACES", "[", "$", "this", "->", "soapVersion", "]", ";", "}" ]
Get the namespace for the current SOAP version. @return string @throws InvalidArgumentException
[ "Get", "the", "namespace", "for", "the", "current", "SOAP", "version", "." ]
47d42012a9836d73642fcc451d90926d70cc9275
https://github.com/dmt-software/jms-soap-serializer/blob/47d42012a9836d73642fcc451d90926d70cc9275/src/SoapSerializationVisitorFactory.php#L82-L89
train
BluePsyduck/MultiCurl
src/Wrapper/Curl.php
Curl.setOption
public function setOption(string $name, $value) { curl_setopt($this->handle, $name, $value); return $this; }
php
public function setOption(string $name, $value) { curl_setopt($this->handle, $name, $value); return $this; }
[ "public", "function", "setOption", "(", "string", "$", "name", ",", "$", "value", ")", "{", "curl_setopt", "(", "$", "this", "->", "handle", ",", "$", "name", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Sets an option for the cURL instance. @param string $name The cURL internal name of the option. @param mixed $value The value to set. @return $this Implementing fluent interface,
[ "Sets", "an", "option", "for", "the", "cURL", "instance", "." ]
9b80a1e59ab21106073effc029aaeb7aa13e2964
https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/Wrapper/Curl.php#L50-L54
train
BluePsyduck/MultiCurl
src/Entity/Request.php
Request.setRequestData
public function setRequestData($requestData) { if (is_array($requestData)) { $this->requestData = http_build_query($requestData); } else { $this->requestData = $requestData; } return $this; }
php
public function setRequestData($requestData) { if (is_array($requestData)) { $this->requestData = http_build_query($requestData); } else { $this->requestData = $requestData; } return $this; }
[ "public", "function", "setRequestData", "(", "$", "requestData", ")", "{", "if", "(", "is_array", "(", "$", "requestData", ")", ")", "{", "$", "this", "->", "requestData", "=", "http_build_query", "(", "$", "requestData", ")", ";", "}", "else", "{", "$", "this", "->", "requestData", "=", "$", "requestData", ";", "}", "return", "$", "this", ";", "}" ]
Sets the request data to send with the request. @param string|array $requestData @return $this Implementing fluent interface.
[ "Sets", "the", "request", "data", "to", "send", "with", "the", "request", "." ]
9b80a1e59ab21106073effc029aaeb7aa13e2964
https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/Entity/Request.php#L147-L155
train
BluePsyduck/MultiCurl
src/Entity/Request.php
Request.setBasicAuth
public function setBasicAuth(string $username, string $password) { $this->basicAuthUsername = $username; $this->basicAuthPassword = $password; return $this; }
php
public function setBasicAuth(string $username, string $password) { $this->basicAuthUsername = $username; $this->basicAuthPassword = $password; return $this; }
[ "public", "function", "setBasicAuth", "(", "string", "$", "username", ",", "string", "$", "password", ")", "{", "$", "this", "->", "basicAuthUsername", "=", "$", "username", ";", "$", "this", "->", "basicAuthPassword", "=", "$", "password", ";", "return", "$", "this", ";", "}" ]
Sets the credentials for the basic authentication. @param string $username The username to use. @param string $password The password to use. @return $this Implementing fluent interface.
[ "Sets", "the", "credentials", "for", "the", "basic", "authentication", "." ]
9b80a1e59ab21106073effc029aaeb7aa13e2964
https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/Entity/Request.php#L201-L206
train
acquia/commerce-manager
modules/acm_sku/src/CategoryManager.php
CategoryManager.synchronizeTreeOffline
public function synchronizeTreeOffline($vocabulary, array $categories, $storeId = '') { $this->resetResults(); $this->loadVocabulary($vocabulary); // Recurse the category tree and create / update nodes. $this->syncCategory($categories, NULL, $storeId); return ($this->results); }
php
public function synchronizeTreeOffline($vocabulary, array $categories, $storeId = '') { $this->resetResults(); $this->loadVocabulary($vocabulary); // Recurse the category tree and create / update nodes. $this->syncCategory($categories, NULL, $storeId); return ($this->results); }
[ "public", "function", "synchronizeTreeOffline", "(", "$", "vocabulary", ",", "array", "$", "categories", ",", "$", "storeId", "=", "''", ")", "{", "$", "this", "->", "resetResults", "(", ")", ";", "$", "this", "->", "loadVocabulary", "(", "$", "vocabulary", ")", ";", "// Recurse the category tree and create / update nodes.", "$", "this", "->", "syncCategory", "(", "$", "categories", ",", "NULL", ",", "$", "storeId", ")", ";", "return", "(", "$", "this", "->", "results", ")", ";", "}" ]
Synchronize categories in offline mode, i.e. not connected to connector. @param string $vocabulary Vocabulary machine name. @param array $categories Category tree to import. @param string $storeId Store ID. @throws \Drupal\Core\TypedData\Exception\ReadOnlyException If the data is read-only. @return array Array summarising updates.
[ "Synchronize", "categories", "in", "offline", "mode", "i", ".", "e", ".", "not", "connected", "to", "connector", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/CategoryManager.php#L168-L176
train
acquia/commerce-manager
modules/acm_promotion/src/Plugin/Block/AcmPromotionBlock.php
AcmPromotionBlock.getPromotionNodes
protected function getPromotionNodes($view_mode) { $nodes = []; // Default to loading all enabled (published) nodes. $query = \Drupal::entityQuery('node') ->condition('type', 'acm_promotion') ->condition('status', NodeInterface::PUBLISHED); if ($view_mode === 'sku_limit') { $viewing_node = \Drupal::routeMatch()->getParameter('node'); if ( !is_null($viewing_node) && $viewing_node->hasField('field_skus') && !empty($viewing_node->get('field_skus')->getValue()) ) { $sku_field = $viewing_node->get('field_skus')->getValue(); $skus = []; foreach ($sku_field as $sku) { $skus[] = $sku['value']; } $query->condition('field_skus', $skus, 'IN'); } } // TODO Consider adding a module alter hook here for $query. $nids = $query->execute(); $nodes = Node::loadMultiple($nids); // TODO Consider adding a module alter hook here for $nodes. return $nodes; }
php
protected function getPromotionNodes($view_mode) { $nodes = []; // Default to loading all enabled (published) nodes. $query = \Drupal::entityQuery('node') ->condition('type', 'acm_promotion') ->condition('status', NodeInterface::PUBLISHED); if ($view_mode === 'sku_limit') { $viewing_node = \Drupal::routeMatch()->getParameter('node'); if ( !is_null($viewing_node) && $viewing_node->hasField('field_skus') && !empty($viewing_node->get('field_skus')->getValue()) ) { $sku_field = $viewing_node->get('field_skus')->getValue(); $skus = []; foreach ($sku_field as $sku) { $skus[] = $sku['value']; } $query->condition('field_skus', $skus, 'IN'); } } // TODO Consider adding a module alter hook here for $query. $nids = $query->execute(); $nodes = Node::loadMultiple($nids); // TODO Consider adding a module alter hook here for $nodes. return $nodes; }
[ "protected", "function", "getPromotionNodes", "(", "$", "view_mode", ")", "{", "$", "nodes", "=", "[", "]", ";", "// Default to loading all enabled (published) nodes.", "$", "query", "=", "\\", "Drupal", "::", "entityQuery", "(", "'node'", ")", "->", "condition", "(", "'type'", ",", "'acm_promotion'", ")", "->", "condition", "(", "'status'", ",", "NodeInterface", "::", "PUBLISHED", ")", ";", "if", "(", "$", "view_mode", "===", "'sku_limit'", ")", "{", "$", "viewing_node", "=", "\\", "Drupal", "::", "routeMatch", "(", ")", "->", "getParameter", "(", "'node'", ")", ";", "if", "(", "!", "is_null", "(", "$", "viewing_node", ")", "&&", "$", "viewing_node", "->", "hasField", "(", "'field_skus'", ")", "&&", "!", "empty", "(", "$", "viewing_node", "->", "get", "(", "'field_skus'", ")", "->", "getValue", "(", ")", ")", ")", "{", "$", "sku_field", "=", "$", "viewing_node", "->", "get", "(", "'field_skus'", ")", "->", "getValue", "(", ")", ";", "$", "skus", "=", "[", "]", ";", "foreach", "(", "$", "sku_field", "as", "$", "sku", ")", "{", "$", "skus", "[", "]", "=", "$", "sku", "[", "'value'", "]", ";", "}", "$", "query", "->", "condition", "(", "'field_skus'", ",", "$", "skus", ",", "'IN'", ")", ";", "}", "}", "// TODO Consider adding a module alter hook here for $query.", "$", "nids", "=", "$", "query", "->", "execute", "(", ")", ";", "$", "nodes", "=", "Node", "::", "loadMultiple", "(", "$", "nids", ")", ";", "// TODO Consider adding a module alter hook here for $nodes.", "return", "$", "nodes", ";", "}" ]
Gets the relavent promotion nodes to be displayed. This method loads the active promotion nodes. @return Drupal\node\Entity\Node[] The promotion node for the user's session.
[ "Gets", "the", "relavent", "promotion", "nodes", "to", "be", "displayed", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_promotion/src/Plugin/Block/AcmPromotionBlock.php#L165-L198
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/FormGroup/StructureFormGroup.php
StructureFormGroup.obj
public function obj() { if ($this->obj === null) { $formGroup = $this->formGroup(); if ($formGroup instanceof self) { $prop = $formGroup->storageProperty(); $val = $formGroup->obj()->propertyValue($prop->ident()); $this->obj = $prop->structureVal($val, [ 'default_data' => true ]); if ($this->obj === null) { $this->obj = clone $prop->structureProto(); } } elseif ($this->form() instanceof ObjectContainerInterface) { $this->obj = $this->form()->obj(); } if ($this->obj === null) { throw new RuntimeException(sprintf( 'The [%1$s] widget has no data model.', static::CLASS )); } } return $this->obj; }
php
public function obj() { if ($this->obj === null) { $formGroup = $this->formGroup(); if ($formGroup instanceof self) { $prop = $formGroup->storageProperty(); $val = $formGroup->obj()->propertyValue($prop->ident()); $this->obj = $prop->structureVal($val, [ 'default_data' => true ]); if ($this->obj === null) { $this->obj = clone $prop->structureProto(); } } elseif ($this->form() instanceof ObjectContainerInterface) { $this->obj = $this->form()->obj(); } if ($this->obj === null) { throw new RuntimeException(sprintf( 'The [%1$s] widget has no data model.', static::CLASS )); } } return $this->obj; }
[ "public", "function", "obj", "(", ")", "{", "if", "(", "$", "this", "->", "obj", "===", "null", ")", "{", "$", "formGroup", "=", "$", "this", "->", "formGroup", "(", ")", ";", "if", "(", "$", "formGroup", "instanceof", "self", ")", "{", "$", "prop", "=", "$", "formGroup", "->", "storageProperty", "(", ")", ";", "$", "val", "=", "$", "formGroup", "->", "obj", "(", ")", "->", "propertyValue", "(", "$", "prop", "->", "ident", "(", ")", ")", ";", "$", "this", "->", "obj", "=", "$", "prop", "->", "structureVal", "(", "$", "val", ",", "[", "'default_data'", "=>", "true", "]", ")", ";", "if", "(", "$", "this", "->", "obj", "===", "null", ")", "{", "$", "this", "->", "obj", "=", "clone", "$", "prop", "->", "structureProto", "(", ")", ";", "}", "}", "elseif", "(", "$", "this", "->", "form", "(", ")", "instanceof", "ObjectContainerInterface", ")", "{", "$", "this", "->", "obj", "=", "$", "this", "->", "form", "(", ")", "->", "obj", "(", ")", ";", "}", "if", "(", "$", "this", "->", "obj", "===", "null", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'The [%1$s] widget has no data model.'", ",", "static", "::", "CLASS", ")", ")", ";", "}", "}", "return", "$", "this", "->", "obj", ";", "}" ]
Retrieve the form's object. @throws RuntimeException If the form doesn't have a model. @return \Charcoal\Model\ModelInterface
[ "Retrieve", "the", "form", "s", "object", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/StructureFormGroup.php#L210-L235
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/FormGroup/StructureFormGroup.php
StructureFormGroup.setStorageProperty
public function setStorageProperty($propertyIdent) { $property = null; if ($propertyIdent instanceof PropertyInterface) { $property = $propertyIdent; $propertyIdent = $property->ident(); } elseif (!is_string($propertyIdent)) { throw new InvalidArgumentException( 'Storage 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($obj) )); } if ($property === null) { $property = $obj->property($propertyIdent); } if ($property instanceof ModelStructureProperty) { $this->storageProperty = $property; } else { throw new UnexpectedValueException(sprintf( '"%s" [%s] is not a model structure property on [%s].', $propertyIdent, (is_object($property) ? get_class($property) : gettype($property)), (is_object($obj) ? get_class($obj) : gettype($obj)) )); } return $this; }
php
public function setStorageProperty($propertyIdent) { $property = null; if ($propertyIdent instanceof PropertyInterface) { $property = $propertyIdent; $propertyIdent = $property->ident(); } elseif (!is_string($propertyIdent)) { throw new InvalidArgumentException( 'Storage 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($obj) )); } if ($property === null) { $property = $obj->property($propertyIdent); } if ($property instanceof ModelStructureProperty) { $this->storageProperty = $property; } else { throw new UnexpectedValueException(sprintf( '"%s" [%s] is not a model structure property on [%s].', $propertyIdent, (is_object($property) ? get_class($property) : gettype($property)), (is_object($obj) ? get_class($obj) : gettype($obj)) )); } return $this; }
[ "public", "function", "setStorageProperty", "(", "$", "propertyIdent", ")", "{", "$", "property", "=", "null", ";", "if", "(", "$", "propertyIdent", "instanceof", "PropertyInterface", ")", "{", "$", "property", "=", "$", "propertyIdent", ";", "$", "propertyIdent", "=", "$", "property", "->", "ident", "(", ")", ";", "}", "elseif", "(", "!", "is_string", "(", "$", "propertyIdent", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Storage 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", "(", "$", "obj", ")", ")", ")", ";", "}", "if", "(", "$", "property", "===", "null", ")", "{", "$", "property", "=", "$", "obj", "->", "property", "(", "$", "propertyIdent", ")", ";", "}", "if", "(", "$", "property", "instanceof", "ModelStructureProperty", ")", "{", "$", "this", "->", "storageProperty", "=", "$", "property", ";", "}", "else", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'\"%s\" [%s] is not a model structure property on [%s].'", ",", "$", "propertyIdent", ",", "(", "is_object", "(", "$", "property", ")", "?", "get_class", "(", "$", "property", ")", ":", "gettype", "(", "$", "property", ")", ")", ",", "(", "is_object", "(", "$", "obj", ")", "?", "get_class", "(", "$", "obj", ")", ":", "gettype", "(", "$", "obj", ")", ")", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the form group's storage target. Must be a property of the form's object model that will receive an associative array of the form group's data. @param string|ModelStructureProperty $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 is invalid. @return self
[ "Set", "the", "form", "group", "s", "storage", "target", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/StructureFormGroup.php#L283-L320
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/FormGroup/StructureFormGroup.php
StructureFormGroup.structProperties
public function structProperties() { $property = $this->storageProperty(); if ($property) { $struct = $property->structureMetadata(); if (isset($struct['properties'])) { return $struct['properties']; } } return []; }
php
public function structProperties() { $property = $this->storageProperty(); if ($property) { $struct = $property->structureMetadata(); if (isset($struct['properties'])) { return $struct['properties']; } } return []; }
[ "public", "function", "structProperties", "(", ")", "{", "$", "property", "=", "$", "this", "->", "storageProperty", "(", ")", ";", "if", "(", "$", "property", ")", "{", "$", "struct", "=", "$", "property", "->", "structureMetadata", "(", ")", ";", "if", "(", "isset", "(", "$", "struct", "[", "'properties'", "]", ")", ")", "{", "return", "$", "struct", "[", "'properties'", "]", ";", "}", "}", "return", "[", "]", ";", "}" ]
Retrieve the properties from the storage property's structure. @return array
[ "Retrieve", "the", "properties", "from", "the", "storage", "property", "s", "structure", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/StructureFormGroup.php#L345-L358
train
acquia/commerce-manager
modules/acm_payment/src/Plugin/CheckoutPane/PaymentMethods.php
PaymentMethods.getPlugin
public function getPlugin($plugin_id) { $cart = $this->getCart(); $paymentMethodManager = \Drupal::service('plugin.manager.acm_payment_method'); return $paymentMethodManager->createInstance($plugin_id, [], $cart); }
php
public function getPlugin($plugin_id) { $cart = $this->getCart(); $paymentMethodManager = \Drupal::service('plugin.manager.acm_payment_method'); return $paymentMethodManager->createInstance($plugin_id, [], $cart); }
[ "public", "function", "getPlugin", "(", "$", "plugin_id", ")", "{", "$", "cart", "=", "$", "this", "->", "getCart", "(", ")", ";", "$", "paymentMethodManager", "=", "\\", "Drupal", "::", "service", "(", "'plugin.manager.acm_payment_method'", ")", ";", "return", "$", "paymentMethodManager", "->", "createInstance", "(", "$", "plugin_id", ",", "[", "]", ",", "$", "cart", ")", ";", "}" ]
Gets a specific payment method plugin. @param string $plugin_id The plugin id.
[ "Gets", "a", "specific", "payment", "method", "plugin", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_payment/src/Plugin/CheckoutPane/PaymentMethods.php#L35-L39
train
acquia/commerce-manager
modules/acm_payment/src/Plugin/CheckoutPane/PaymentMethods.php
PaymentMethods.getSelectedPlugin
public function getSelectedPlugin() { $cart = $this->getCart(); $plugin_id = $cart->getPaymentMethod(FALSE); return $this->getPlugin($plugin_id); }
php
public function getSelectedPlugin() { $cart = $this->getCart(); $plugin_id = $cart->getPaymentMethod(FALSE); return $this->getPlugin($plugin_id); }
[ "public", "function", "getSelectedPlugin", "(", ")", "{", "$", "cart", "=", "$", "this", "->", "getCart", "(", ")", ";", "$", "plugin_id", "=", "$", "cart", "->", "getPaymentMethod", "(", "FALSE", ")", ";", "return", "$", "this", "->", "getPlugin", "(", "$", "plugin_id", ")", ";", "}" ]
Gets the customer selected plugin.
[ "Gets", "the", "customer", "selected", "plugin", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_payment/src/Plugin/CheckoutPane/PaymentMethods.php#L44-L48
train
acquia/commerce-manager
modules/acm/src/Connector/IngestAPIWrapper.php
IngestAPIWrapper.productFullSync
public function productFullSync($skus = '', $product_page_size = 0, $store_id = "", $langcode = "", $categoryId = "") { if (empty($product_page_size)) { $product_page_size = (int) $this->productPageSize; } else { $product_page_size = (int) $product_page_size; } if (!($store_id && $langcode)) { $languageMap = $this->i18nHelper->getStoreLanguageMapping(); } else { $languageMap = [$langcode => $store_id]; } foreach ($languageMap as $langcode => $store_id) { if (empty($store_id)) { continue; } // At 20180228 store_id *is* acm_uuid is enforced // $store_id is sent in the query string // $acm_uuid is sent in the X-ACM-UUID header // It must only be this way: $acm_uuid = $store_id; if ($this->debug && !empty($this->debugDir)) { // Export product data into file. $filename = $this->debugDir . '/products_' . $langcode . '.data'; $fp = fopen($filename, 'w'); fclose($fp); } $endpoint = $this->apiVersion . '/ingest/product/sync'; // $store_id is sent in the query string. $doReq = function ($client, $opt) use ($endpoint, $store_id, $skus, $product_page_size, $categoryId) { if ($product_page_size > 0) { $opt['query']['page_size'] = $product_page_size; } if (!empty($categoryId)) { $opt['query']['category_id'] = (string) $categoryId; // Function tryIngestRequest always sets the skus. // But in this case (category sync) we force no skus // always send all the skus in the category. unset($opt['query']['skus']); } elseif (!empty($skus)) { $opt['query']['skus'] = $skus; } $opt['query']['store_id'] = $store_id; // To allow hmac sign to be verified properly we need them in asc order. // Really? ksort($opt['query']); return $client->post($endpoint, $opt); }; try { // $acm_uuid is set in the header of the client. $this->tryIngestRequest($doReq, 'productFullSync', 'products', $skus, $acm_uuid); } catch (ConnectorException $e) { throw new RouteException(__FUNCTION__, $e->getMessage(), $e->getCode()); } } }
php
public function productFullSync($skus = '', $product_page_size = 0, $store_id = "", $langcode = "", $categoryId = "") { if (empty($product_page_size)) { $product_page_size = (int) $this->productPageSize; } else { $product_page_size = (int) $product_page_size; } if (!($store_id && $langcode)) { $languageMap = $this->i18nHelper->getStoreLanguageMapping(); } else { $languageMap = [$langcode => $store_id]; } foreach ($languageMap as $langcode => $store_id) { if (empty($store_id)) { continue; } // At 20180228 store_id *is* acm_uuid is enforced // $store_id is sent in the query string // $acm_uuid is sent in the X-ACM-UUID header // It must only be this way: $acm_uuid = $store_id; if ($this->debug && !empty($this->debugDir)) { // Export product data into file. $filename = $this->debugDir . '/products_' . $langcode . '.data'; $fp = fopen($filename, 'w'); fclose($fp); } $endpoint = $this->apiVersion . '/ingest/product/sync'; // $store_id is sent in the query string. $doReq = function ($client, $opt) use ($endpoint, $store_id, $skus, $product_page_size, $categoryId) { if ($product_page_size > 0) { $opt['query']['page_size'] = $product_page_size; } if (!empty($categoryId)) { $opt['query']['category_id'] = (string) $categoryId; // Function tryIngestRequest always sets the skus. // But in this case (category sync) we force no skus // always send all the skus in the category. unset($opt['query']['skus']); } elseif (!empty($skus)) { $opt['query']['skus'] = $skus; } $opt['query']['store_id'] = $store_id; // To allow hmac sign to be verified properly we need them in asc order. // Really? ksort($opt['query']); return $client->post($endpoint, $opt); }; try { // $acm_uuid is set in the header of the client. $this->tryIngestRequest($doReq, 'productFullSync', 'products', $skus, $acm_uuid); } catch (ConnectorException $e) { throw new RouteException(__FUNCTION__, $e->getMessage(), $e->getCode()); } } }
[ "public", "function", "productFullSync", "(", "$", "skus", "=", "''", ",", "$", "product_page_size", "=", "0", ",", "$", "store_id", "=", "\"\"", ",", "$", "langcode", "=", "\"\"", ",", "$", "categoryId", "=", "\"\"", ")", "{", "if", "(", "empty", "(", "$", "product_page_size", ")", ")", "{", "$", "product_page_size", "=", "(", "int", ")", "$", "this", "->", "productPageSize", ";", "}", "else", "{", "$", "product_page_size", "=", "(", "int", ")", "$", "product_page_size", ";", "}", "if", "(", "!", "(", "$", "store_id", "&&", "$", "langcode", ")", ")", "{", "$", "languageMap", "=", "$", "this", "->", "i18nHelper", "->", "getStoreLanguageMapping", "(", ")", ";", "}", "else", "{", "$", "languageMap", "=", "[", "$", "langcode", "=>", "$", "store_id", "]", ";", "}", "foreach", "(", "$", "languageMap", "as", "$", "langcode", "=>", "$", "store_id", ")", "{", "if", "(", "empty", "(", "$", "store_id", ")", ")", "{", "continue", ";", "}", "// At 20180228 store_id *is* acm_uuid is enforced", "// $store_id is sent in the query string", "// $acm_uuid is sent in the X-ACM-UUID header", "// It must only be this way:", "$", "acm_uuid", "=", "$", "store_id", ";", "if", "(", "$", "this", "->", "debug", "&&", "!", "empty", "(", "$", "this", "->", "debugDir", ")", ")", "{", "// Export product data into file.", "$", "filename", "=", "$", "this", "->", "debugDir", ".", "'/products_'", ".", "$", "langcode", ".", "'.data'", ";", "$", "fp", "=", "fopen", "(", "$", "filename", ",", "'w'", ")", ";", "fclose", "(", "$", "fp", ")", ";", "}", "$", "endpoint", "=", "$", "this", "->", "apiVersion", ".", "'/ingest/product/sync'", ";", "// $store_id is sent in the query string.", "$", "doReq", "=", "function", "(", "$", "client", ",", "$", "opt", ")", "use", "(", "$", "endpoint", ",", "$", "store_id", ",", "$", "skus", ",", "$", "product_page_size", ",", "$", "categoryId", ")", "{", "if", "(", "$", "product_page_size", ">", "0", ")", "{", "$", "opt", "[", "'query'", "]", "[", "'page_size'", "]", "=", "$", "product_page_size", ";", "}", "if", "(", "!", "empty", "(", "$", "categoryId", ")", ")", "{", "$", "opt", "[", "'query'", "]", "[", "'category_id'", "]", "=", "(", "string", ")", "$", "categoryId", ";", "// Function tryIngestRequest always sets the skus.", "// But in this case (category sync) we force no skus", "// always send all the skus in the category.", "unset", "(", "$", "opt", "[", "'query'", "]", "[", "'skus'", "]", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "skus", ")", ")", "{", "$", "opt", "[", "'query'", "]", "[", "'skus'", "]", "=", "$", "skus", ";", "}", "$", "opt", "[", "'query'", "]", "[", "'store_id'", "]", "=", "$", "store_id", ";", "// To allow hmac sign to be verified properly we need them in asc order.", "// Really?", "ksort", "(", "$", "opt", "[", "'query'", "]", ")", ";", "return", "$", "client", "->", "post", "(", "$", "endpoint", ",", "$", "opt", ")", ";", "}", ";", "try", "{", "// $acm_uuid is set in the header of the client.", "$", "this", "->", "tryIngestRequest", "(", "$", "doReq", ",", "'productFullSync'", ",", "'products'", ",", "$", "skus", ",", "$", "acm_uuid", ")", ";", "}", "catch", "(", "ConnectorException", "$", "e", ")", "{", "throw", "new", "RouteException", "(", "__FUNCTION__", ",", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ")", ";", "}", "}", "}" ]
Performs full connector sync. @param string $skus List of SKUs. @param int $product_page_size Override for product page size. @param string $store_id Optional store_id if specified you must specify a langcode. @param string $langcode Optional laguage code. If specified you must specify a $storeId. @param string $categoryId Optional. The category ID to sync from. If specified, skus are ignored and all skus of that category are synchronised.
[ "Performs", "full", "connector", "sync", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Connector/IngestAPIWrapper.php#L81-L151
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/PermalinkInput.php
PermalinkInput.viewLink
public function viewLink() { $link = null; $locale = $this->lang(); if ($locale !== null) { $translator = $this->translator(); $origLocale = $translator->getLocale(); $translator->setLocale($this->lang()); $link = $this->renderTemplate('{{# withBaseUrl }}{{ obj.url }}{{/ withBaseUrl }}'); $translator->setLocale($origLocale); } return $link; }
php
public function viewLink() { $link = null; $locale = $this->lang(); if ($locale !== null) { $translator = $this->translator(); $origLocale = $translator->getLocale(); $translator->setLocale($this->lang()); $link = $this->renderTemplate('{{# withBaseUrl }}{{ obj.url }}{{/ withBaseUrl }}'); $translator->setLocale($origLocale); } return $link; }
[ "public", "function", "viewLink", "(", ")", "{", "$", "link", "=", "null", ";", "$", "locale", "=", "$", "this", "->", "lang", "(", ")", ";", "if", "(", "$", "locale", "!==", "null", ")", "{", "$", "translator", "=", "$", "this", "->", "translator", "(", ")", ";", "$", "origLocale", "=", "$", "translator", "->", "getLocale", "(", ")", ";", "$", "translator", "->", "setLocale", "(", "$", "this", "->", "lang", "(", ")", ")", ";", "$", "link", "=", "$", "this", "->", "renderTemplate", "(", "'{{# withBaseUrl }}{{ obj.url }}{{/ withBaseUrl }}'", ")", ";", "$", "translator", "->", "setLocale", "(", "$", "origLocale", ")", ";", "}", "return", "$", "link", ";", "}" ]
Get the permalink's absolute URI. @return string|null
[ "Get", "the", "permalink", "s", "absolute", "URI", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/PermalinkInput.php#L75-L88
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/PermalinkInput.php
PermalinkInput.baseRoute
public function baseRoute() { if ($this->baseRoute === null) { $this->baseRoute = $this->baseUrl(); } $link = $this->baseRoute; $locale = $this->lang(); if ($locale !== null) { $translator = $this->translator(); $origLocale = $translator->getLocale(); $translator->setLocale($this->lang()); $link = $this->renderTemplate((string)$link); $translator->setLocale($origLocale); } return rtrim((string)$link, '/').'/'; }
php
public function baseRoute() { if ($this->baseRoute === null) { $this->baseRoute = $this->baseUrl(); } $link = $this->baseRoute; $locale = $this->lang(); if ($locale !== null) { $translator = $this->translator(); $origLocale = $translator->getLocale(); $translator->setLocale($this->lang()); $link = $this->renderTemplate((string)$link); $translator->setLocale($origLocale); } return rtrim((string)$link, '/').'/'; }
[ "public", "function", "baseRoute", "(", ")", "{", "if", "(", "$", "this", "->", "baseRoute", "===", "null", ")", "{", "$", "this", "->", "baseRoute", "=", "$", "this", "->", "baseUrl", "(", ")", ";", "}", "$", "link", "=", "$", "this", "->", "baseRoute", ";", "$", "locale", "=", "$", "this", "->", "lang", "(", ")", ";", "if", "(", "$", "locale", "!==", "null", ")", "{", "$", "translator", "=", "$", "this", "->", "translator", "(", ")", ";", "$", "origLocale", "=", "$", "translator", "->", "getLocale", "(", ")", ";", "$", "translator", "->", "setLocale", "(", "$", "this", "->", "lang", "(", ")", ")", ";", "$", "link", "=", "$", "this", "->", "renderTemplate", "(", "(", "string", ")", "$", "link", ")", ";", "$", "translator", "->", "setLocale", "(", "$", "origLocale", ")", ";", "}", "return", "rtrim", "(", "(", "string", ")", "$", "link", ",", "'/'", ")", ".", "'/'", ";", "}" ]
Get the permalink's immutable base. @return string|null
[ "Get", "the", "permalink", "s", "immutable", "base", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/PermalinkInput.php#L107-L124
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/PermalinkInput.php
PermalinkInput.editableRoute
public function editableRoute() { $link = $this->inputVal(); if (empty($link)) { $link = $this->placeholder(); } return $link; }
php
public function editableRoute() { $link = $this->inputVal(); if (empty($link)) { $link = $this->placeholder(); } return $link; }
[ "public", "function", "editableRoute", "(", ")", "{", "$", "link", "=", "$", "this", "->", "inputVal", "(", ")", ";", "if", "(", "empty", "(", "$", "link", ")", ")", "{", "$", "link", "=", "$", "this", "->", "placeholder", "(", ")", ";", "}", "return", "$", "link", ";", "}" ]
Get the permalink's editable part. @return string|null
[ "Get", "the", "permalink", "s", "editable", "part", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/PermalinkInput.php#L131-L139
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/PermalinkInput.php
PermalinkInput.baseUrl
public function baseUrl() { if (!isset($this->baseUrl)) { throw new RuntimeException(sprintf( 'The base URI is not defined for [%s]', get_class($this) )); } return $this->baseUrl; }
php
public function baseUrl() { if (!isset($this->baseUrl)) { throw new RuntimeException(sprintf( 'The base URI is not defined for [%s]', get_class($this) )); } return $this->baseUrl; }
[ "public", "function", "baseUrl", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "baseUrl", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'The base URI is not defined for [%s]'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "return", "$", "this", "->", "baseUrl", ";", "}" ]
Get the base URI of the project. @throws RuntimeException If the base URI is missing. @return UriInterface|null
[ "Get", "the", "base", "URI", "of", "the", "project", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/PermalinkInput.php#L159-L169
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/PermalinkInput.php
PermalinkInput.samples
public function samples() { if ($this->p()->l10n() === false) { $origLang = $this->lang(); $locales = $this->translator()->availableLocales(); $sampleId = $this->sampleId(); foreach ($locales as $langCode) { $this->setSampleId($sampleId.'_'.$langCode); $this->setLang($langCode); yield $this; } $this->setSampleId($sampleId); $this->setLang($origLang); } else { yield $this; } }
php
public function samples() { if ($this->p()->l10n() === false) { $origLang = $this->lang(); $locales = $this->translator()->availableLocales(); $sampleId = $this->sampleId(); foreach ($locales as $langCode) { $this->setSampleId($sampleId.'_'.$langCode); $this->setLang($langCode); yield $this; } $this->setSampleId($sampleId); $this->setLang($origLang); } else { yield $this; } }
[ "public", "function", "samples", "(", ")", "{", "if", "(", "$", "this", "->", "p", "(", ")", "->", "l10n", "(", ")", "===", "false", ")", "{", "$", "origLang", "=", "$", "this", "->", "lang", "(", ")", ";", "$", "locales", "=", "$", "this", "->", "translator", "(", ")", "->", "availableLocales", "(", ")", ";", "$", "sampleId", "=", "$", "this", "->", "sampleId", "(", ")", ";", "foreach", "(", "$", "locales", "as", "$", "langCode", ")", "{", "$", "this", "->", "setSampleId", "(", "$", "sampleId", ".", "'_'", ".", "$", "langCode", ")", ";", "$", "this", "->", "setLang", "(", "$", "langCode", ")", ";", "yield", "$", "this", ";", "}", "$", "this", "->", "setSampleId", "(", "$", "sampleId", ")", ";", "$", "this", "->", "setLang", "(", "$", "origLang", ")", ";", "}", "else", "{", "yield", "$", "this", ";", "}", "}" ]
Iterate the samples to display. @return \Generator
[ "Iterate", "the", "samples", "to", "display", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/PermalinkInput.php#L176-L193
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/PermalinkInput.php
PermalinkInput.sampleId
public function sampleId() { if (!$this->sampleId) { $this->sampleId = $this->inputId() ?: $this->generateSampleId(); } return $this->sampleId; }
php
public function sampleId() { if (!$this->sampleId) { $this->sampleId = $this->inputId() ?: $this->generateSampleId(); } return $this->sampleId; }
[ "public", "function", "sampleId", "(", ")", "{", "if", "(", "!", "$", "this", "->", "sampleId", ")", "{", "$", "this", "->", "sampleId", "=", "$", "this", "->", "inputId", "(", ")", "?", ":", "$", "this", "->", "generateSampleId", "(", ")", ";", "}", "return", "$", "this", "->", "sampleId", ";", "}" ]
Get the sample ID. If none was previously set then a unique random one will be generated. @return string
[ "Get", "the", "sample", "ID", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/PermalinkInput.php#L216-L223
train
acquia/commerce-manager
modules/acm_sku/src/CartFormHelper.php
CartFormHelper.getConfigurableAttributeWeights
public function getConfigurableAttributeWeights($attribute_set = 'default') { $attribute_set = strtolower($attribute_set); $weights = $this->config->get('attribute_weights'); $set_weights = $weights[$attribute_set] ?? $weights['default']; asort($set_weights); return $set_weights; }
php
public function getConfigurableAttributeWeights($attribute_set = 'default') { $attribute_set = strtolower($attribute_set); $weights = $this->config->get('attribute_weights'); $set_weights = $weights[$attribute_set] ?? $weights['default']; asort($set_weights); return $set_weights; }
[ "public", "function", "getConfigurableAttributeWeights", "(", "$", "attribute_set", "=", "'default'", ")", "{", "$", "attribute_set", "=", "strtolower", "(", "$", "attribute_set", ")", ";", "$", "weights", "=", "$", "this", "->", "config", "->", "get", "(", "'attribute_weights'", ")", ";", "$", "set_weights", "=", "$", "weights", "[", "$", "attribute_set", "]", "??", "$", "weights", "[", "'default'", "]", ";", "asort", "(", "$", "set_weights", ")", ";", "return", "$", "set_weights", ";", "}" ]
Get the attribute codes with weight for particular attribute set. @param string $attribute_set Attribute set. @return array Attribute codes with weight as value.
[ "Get", "the", "attribute", "codes", "with", "weight", "for", "particular", "attribute", "set", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/CartFormHelper.php#L50-L56
train
acquia/commerce-manager
modules/acm_sku/src/CartFormHelper.php
CartFormHelper.setConfigurableAttributeWeights
public function setConfigurableAttributeWeights($attribute_set = 'default', array $weights = []) { $attribute_set = strtolower($attribute_set); // Update weights for particular attribute set in config. $existing_weights = $this->config->get('attribute_weights'); $existing_weights[$attribute_set] = $weights; $config = $this->configFactory->getEditable(self::CONFIG_KEY); $config->set('attribute_weights', $existing_weights); $config->save(); // Reload config. $this->config = $this->configFactory->get(self::CONFIG_KEY); }
php
public function setConfigurableAttributeWeights($attribute_set = 'default', array $weights = []) { $attribute_set = strtolower($attribute_set); // Update weights for particular attribute set in config. $existing_weights = $this->config->get('attribute_weights'); $existing_weights[$attribute_set] = $weights; $config = $this->configFactory->getEditable(self::CONFIG_KEY); $config->set('attribute_weights', $existing_weights); $config->save(); // Reload config. $this->config = $this->configFactory->get(self::CONFIG_KEY); }
[ "public", "function", "setConfigurableAttributeWeights", "(", "$", "attribute_set", "=", "'default'", ",", "array", "$", "weights", "=", "[", "]", ")", "{", "$", "attribute_set", "=", "strtolower", "(", "$", "attribute_set", ")", ";", "// Update weights for particular attribute set in config.", "$", "existing_weights", "=", "$", "this", "->", "config", "->", "get", "(", "'attribute_weights'", ")", ";", "$", "existing_weights", "[", "$", "attribute_set", "]", "=", "$", "weights", ";", "$", "config", "=", "$", "this", "->", "configFactory", "->", "getEditable", "(", "self", "::", "CONFIG_KEY", ")", ";", "$", "config", "->", "set", "(", "'attribute_weights'", ",", "$", "existing_weights", ")", ";", "$", "config", "->", "save", "(", ")", ";", "// Reload config.", "$", "this", "->", "config", "=", "$", "this", "->", "configFactory", "->", "get", "(", "self", "::", "CONFIG_KEY", ")", ";", "}" ]
Set the attribute codes with weight for particular attribute set. @param string $attribute_set Attribute set. @param array $weights Weights to set for the selected attribute set.
[ "Set", "the", "attribute", "codes", "with", "weight", "for", "particular", "attribute", "set", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/CartFormHelper.php#L66-L79
train
acquia/commerce-manager
modules/acm_sku/src/CartFormHelper.php
CartFormHelper.getFirstAttribute
public function getFirstAttribute($attribute_set = 'default') { $weights = $this->getConfigurableAttributeWeights($attribute_set); $attributes = $weights ? array_keys($weights) : []; return !empty($attributes) ? reset($attributes) : ''; }
php
public function getFirstAttribute($attribute_set = 'default') { $weights = $this->getConfigurableAttributeWeights($attribute_set); $attributes = $weights ? array_keys($weights) : []; return !empty($attributes) ? reset($attributes) : ''; }
[ "public", "function", "getFirstAttribute", "(", "$", "attribute_set", "=", "'default'", ")", "{", "$", "weights", "=", "$", "this", "->", "getConfigurableAttributeWeights", "(", "$", "attribute_set", ")", ";", "$", "attributes", "=", "$", "weights", "?", "array_keys", "(", "$", "weights", ")", ":", "[", "]", ";", "return", "!", "empty", "(", "$", "attributes", ")", "?", "reset", "(", "$", "attributes", ")", ":", "''", ";", "}" ]
Get first attribute code based on weights for particular attribute set. @param string $attribute_set Attribute set. @return string First attribute code based on weights for particular attribute set.
[ "Get", "first", "attribute", "code", "based", "on", "weights", "for", "particular", "attribute", "set", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/CartFormHelper.php#L104-L108
train
acquia/commerce-manager
modules/acm/src/I18nHelper.php
I18nHelper.getStoreLanguageMapping
public function getStoreLanguageMapping() { $mapping = []; $languages = $this->languageManager->getLanguages(); // Prepare the alternate locale data. foreach ($languages as $lang => $language) { // For default language, we access the config directly. if ($lang == $this->languageManager->getDefaultLanguage()->getId()) { $config = $this->configFactory->get('acm.store'); } // We get store id from translated config for other languages. else { $config = $this->languageManager->getLanguageConfigOverride($lang, 'acm.store'); } $mapping[$lang] = $config->get('store_id'); } return $mapping; }
php
public function getStoreLanguageMapping() { $mapping = []; $languages = $this->languageManager->getLanguages(); // Prepare the alternate locale data. foreach ($languages as $lang => $language) { // For default language, we access the config directly. if ($lang == $this->languageManager->getDefaultLanguage()->getId()) { $config = $this->configFactory->get('acm.store'); } // We get store id from translated config for other languages. else { $config = $this->languageManager->getLanguageConfigOverride($lang, 'acm.store'); } $mapping[$lang] = $config->get('store_id'); } return $mapping; }
[ "public", "function", "getStoreLanguageMapping", "(", ")", "{", "$", "mapping", "=", "[", "]", ";", "$", "languages", "=", "$", "this", "->", "languageManager", "->", "getLanguages", "(", ")", ";", "// Prepare the alternate locale data.", "foreach", "(", "$", "languages", "as", "$", "lang", "=>", "$", "language", ")", "{", "// For default language, we access the config directly.", "if", "(", "$", "lang", "==", "$", "this", "->", "languageManager", "->", "getDefaultLanguage", "(", ")", "->", "getId", "(", ")", ")", "{", "$", "config", "=", "$", "this", "->", "configFactory", "->", "get", "(", "'acm.store'", ")", ";", "}", "// We get store id from translated config for other languages.", "else", "{", "$", "config", "=", "$", "this", "->", "languageManager", "->", "getLanguageConfigOverride", "(", "$", "lang", ",", "'acm.store'", ")", ";", "}", "$", "mapping", "[", "$", "lang", "]", "=", "$", "config", "->", "get", "(", "'store_id'", ")", ";", "}", "return", "$", "mapping", ";", "}" ]
Helper method to get mapping of all store ids and language codes. @return array Mapping array.
[ "Helper", "method", "to", "get", "mapping", "of", "all", "store", "ids", "and", "language", "codes", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/I18nHelper.php#L47-L67
train
acquia/commerce-manager
modules/acm/src/I18nHelper.php
I18nHelper.getStoreIdFromLangcode
public function getStoreIdFromLangcode($langcode = '') { if (empty($langcode)) { $langcode = $this->languageManager->getCurrentLanguage()->getId(); } $mapping = $this->getStoreLanguageMapping(); return !empty($mapping[$langcode]) ? $mapping[$langcode] : NULL; }
php
public function getStoreIdFromLangcode($langcode = '') { if (empty($langcode)) { $langcode = $this->languageManager->getCurrentLanguage()->getId(); } $mapping = $this->getStoreLanguageMapping(); return !empty($mapping[$langcode]) ? $mapping[$langcode] : NULL; }
[ "public", "function", "getStoreIdFromLangcode", "(", "$", "langcode", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "langcode", ")", ")", "{", "$", "langcode", "=", "$", "this", "->", "languageManager", "->", "getCurrentLanguage", "(", ")", "->", "getId", "(", ")", ";", "}", "$", "mapping", "=", "$", "this", "->", "getStoreLanguageMapping", "(", ")", ";", "return", "!", "empty", "(", "$", "mapping", "[", "$", "langcode", "]", ")", "?", "$", "mapping", "[", "$", "langcode", "]", ":", "NULL", ";", "}" ]
Helper method to get store id from language code. @param string $langcode Language code to convert to store id. @return string|null Store id if available as string or null.
[ "Helper", "method", "to", "get", "store", "id", "from", "language", "code", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/I18nHelper.php#L78-L84
train
acquia/commerce-manager
modules/acm/src/I18nHelper.php
I18nHelper.getLangcodeFromStoreId
public function getLangcodeFromStoreId($store_id) { $mapping = $this->getStoreLanguageMapping(); $mapping = is_array($mapping) && !empty($mapping) ? array_flip(array_filter($mapping)) : NULL; if (empty($store_id)) { return array_shift($mapping); } return !empty($mapping[$store_id]) ? $mapping[$store_id] : NULL; }
php
public function getLangcodeFromStoreId($store_id) { $mapping = $this->getStoreLanguageMapping(); $mapping = is_array($mapping) && !empty($mapping) ? array_flip(array_filter($mapping)) : NULL; if (empty($store_id)) { return array_shift($mapping); } return !empty($mapping[$store_id]) ? $mapping[$store_id] : NULL; }
[ "public", "function", "getLangcodeFromStoreId", "(", "$", "store_id", ")", "{", "$", "mapping", "=", "$", "this", "->", "getStoreLanguageMapping", "(", ")", ";", "$", "mapping", "=", "is_array", "(", "$", "mapping", ")", "&&", "!", "empty", "(", "$", "mapping", ")", "?", "array_flip", "(", "array_filter", "(", "$", "mapping", ")", ")", ":", "NULL", ";", "if", "(", "empty", "(", "$", "store_id", ")", ")", "{", "return", "array_shift", "(", "$", "mapping", ")", ";", "}", "return", "!", "empty", "(", "$", "mapping", "[", "$", "store_id", "]", ")", "?", "$", "mapping", "[", "$", "store_id", "]", ":", "NULL", ";", "}" ]
Helper method to get language code from store id. @param string $store_id Store id to convert to language code. @return string|null Language code if available or null.
[ "Helper", "method", "to", "get", "language", "code", "from", "store", "id", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/I18nHelper.php#L95-L104
train
acquia/commerce-manager
modules/acm/src/I18nHelper.php
I18nHelper.formatPrice
public function formatPrice($price) { // Fetch the config. $config = $this->configFactory->get('acm.currency'); // Get currency with the correct locale. $locale = \Drupal::languageManager()->getCurrentLanguage()->getId(); $currency = \Drupal::service('repository.currency'); $numberFormat = \Drupal::service('repository.number_format'); $currencyFormatter = new CurrencyFormatter($numberFormat, $currency, ['locale' => $locale]); $currencyCode = $currency->get($config->get('currency_code'))->getCurrencyCode(); return $currencyFormatter->format($price, $currencyCode); }
php
public function formatPrice($price) { // Fetch the config. $config = $this->configFactory->get('acm.currency'); // Get currency with the correct locale. $locale = \Drupal::languageManager()->getCurrentLanguage()->getId(); $currency = \Drupal::service('repository.currency'); $numberFormat = \Drupal::service('repository.number_format'); $currencyFormatter = new CurrencyFormatter($numberFormat, $currency, ['locale' => $locale]); $currencyCode = $currency->get($config->get('currency_code'))->getCurrencyCode(); return $currencyFormatter->format($price, $currencyCode); }
[ "public", "function", "formatPrice", "(", "$", "price", ")", "{", "// Fetch the config.", "$", "config", "=", "$", "this", "->", "configFactory", "->", "get", "(", "'acm.currency'", ")", ";", "// Get currency with the correct locale.", "$", "locale", "=", "\\", "Drupal", "::", "languageManager", "(", ")", "->", "getCurrentLanguage", "(", ")", "->", "getId", "(", ")", ";", "$", "currency", "=", "\\", "Drupal", "::", "service", "(", "'repository.currency'", ")", ";", "$", "numberFormat", "=", "\\", "Drupal", "::", "service", "(", "'repository.number_format'", ")", ";", "$", "currencyFormatter", "=", "new", "CurrencyFormatter", "(", "$", "numberFormat", ",", "$", "currency", ",", "[", "'locale'", "=>", "$", "locale", "]", ")", ";", "$", "currencyCode", "=", "$", "currency", "->", "get", "(", "$", "config", "->", "get", "(", "'currency_code'", ")", ")", "->", "getCurrencyCode", "(", ")", ";", "return", "$", "currencyFormatter", "->", "format", "(", "$", "price", ",", "$", "currencyCode", ")", ";", "}" ]
Helper function to format price string. @param string $price Price vaue we want to format. @return string Formatted price string.
[ "Helper", "function", "to", "format", "price", "string", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/I18nHelper.php#L115-L128
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractPropertyInput.php
AbstractPropertyInput.setPlaceholder
public function setPlaceholder($placeholder) { if ($placeholder === null || $placeholder === '') { $this->placeholder = ''; return $this; } $this->placeholder = $this->translator()->translation($placeholder); if ($this->placeholder instanceof Translation) { $this->placeholder->isRendered = false; } else { $this->placeholder = ''; } return $this; }
php
public function setPlaceholder($placeholder) { if ($placeholder === null || $placeholder === '') { $this->placeholder = ''; return $this; } $this->placeholder = $this->translator()->translation($placeholder); if ($this->placeholder instanceof Translation) { $this->placeholder->isRendered = false; } else { $this->placeholder = ''; } return $this; }
[ "public", "function", "setPlaceholder", "(", "$", "placeholder", ")", "{", "if", "(", "$", "placeholder", "===", "null", "||", "$", "placeholder", "===", "''", ")", "{", "$", "this", "->", "placeholder", "=", "''", ";", "return", "$", "this", ";", "}", "$", "this", "->", "placeholder", "=", "$", "this", "->", "translator", "(", ")", "->", "translation", "(", "$", "placeholder", ")", ";", "if", "(", "$", "this", "->", "placeholder", "instanceof", "Translation", ")", "{", "$", "this", "->", "placeholder", "->", "isRendered", "=", "false", ";", "}", "else", "{", "$", "this", "->", "placeholder", "=", "''", ";", "}", "return", "$", "this", ";", "}" ]
Set the form control's placeholder. A placeholder is a hint to the user of what can be entered in the property control. @param mixed $placeholder The placeholder attribute. @return self
[ "Set", "the", "form", "control", "s", "placeholder", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractPropertyInput.php#L389-L404
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractPropertyInput.php
AbstractPropertyInput.placeholder
public function placeholder() { if ($this->placeholder === null) { $metadata = $this->metadata(); if (isset($metadata['data']['placeholder'])) { $this->setPlaceholder($metadata['data']['placeholder']); } else { $this->placeholder = ''; } } if ($this->placeholder instanceof Translation) { if (isset($this->placeholder->isRendered) && $this->placeholder->isRendered === false) { $this->placeholder = $this->renderTranslatableTemplate($this->placeholder); } if ($this->lang()) { return $this->placeholder[$this->lang()]; } } return $this->placeholder; }
php
public function placeholder() { if ($this->placeholder === null) { $metadata = $this->metadata(); if (isset($metadata['data']['placeholder'])) { $this->setPlaceholder($metadata['data']['placeholder']); } else { $this->placeholder = ''; } } if ($this->placeholder instanceof Translation) { if (isset($this->placeholder->isRendered) && $this->placeholder->isRendered === false) { $this->placeholder = $this->renderTranslatableTemplate($this->placeholder); } if ($this->lang()) { return $this->placeholder[$this->lang()]; } } return $this->placeholder; }
[ "public", "function", "placeholder", "(", ")", "{", "if", "(", "$", "this", "->", "placeholder", "===", "null", ")", "{", "$", "metadata", "=", "$", "this", "->", "metadata", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "'data'", "]", "[", "'placeholder'", "]", ")", ")", "{", "$", "this", "->", "setPlaceholder", "(", "$", "metadata", "[", "'data'", "]", "[", "'placeholder'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "placeholder", "=", "''", ";", "}", "}", "if", "(", "$", "this", "->", "placeholder", "instanceof", "Translation", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "placeholder", "->", "isRendered", ")", "&&", "$", "this", "->", "placeholder", "->", "isRendered", "===", "false", ")", "{", "$", "this", "->", "placeholder", "=", "$", "this", "->", "renderTranslatableTemplate", "(", "$", "this", "->", "placeholder", ")", ";", "}", "if", "(", "$", "this", "->", "lang", "(", ")", ")", "{", "return", "$", "this", "->", "placeholder", "[", "$", "this", "->", "lang", "(", ")", "]", ";", "}", "}", "return", "$", "this", "->", "placeholder", ";", "}" ]
Retrieve the placeholder. @return Translation|string|null
[ "Retrieve", "the", "placeholder", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractPropertyInput.php#L411-L434
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractPropertyInput.php
AbstractPropertyInput.inputName
public function inputName() { if ($this->inputName) { $name = $this->inputName; } else { $name = $this->propertyIdent(); } if ($this->p()->l10n()) { $name .= '['.$this->lang().']'; } if ($this->multiple()) { $name .= '[]'; } return $name; }
php
public function inputName() { if ($this->inputName) { $name = $this->inputName; } else { $name = $this->propertyIdent(); } if ($this->p()->l10n()) { $name .= '['.$this->lang().']'; } if ($this->multiple()) { $name .= '[]'; } return $name; }
[ "public", "function", "inputName", "(", ")", "{", "if", "(", "$", "this", "->", "inputName", ")", "{", "$", "name", "=", "$", "this", "->", "inputName", ";", "}", "else", "{", "$", "name", "=", "$", "this", "->", "propertyIdent", "(", ")", ";", "}", "if", "(", "$", "this", "->", "p", "(", ")", "->", "l10n", "(", ")", ")", "{", "$", "name", ".=", "'['", ".", "$", "this", "->", "lang", "(", ")", ".", "']'", ";", "}", "if", "(", "$", "this", "->", "multiple", "(", ")", ")", "{", "$", "name", ".=", "'[]'", ";", "}", "return", "$", "name", ";", "}" ]
Retrieve the input name. The input name should always be the property's ident. @return string
[ "Retrieve", "the", "input", "name", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractPropertyInput.php#L511-L528
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractPropertyInput.php
AbstractPropertyInput.renderTranslatableTemplate
public function renderTranslatableTemplate($templateString) { if ($templateString instanceof Translation) { $origLang = $this->translator()->getLocale(); foreach ($this->translator()->availableLocales() as $lang) { if (!isset($templateString[$lang])) { continue; } $translation = $templateString[$lang]; $isBlank = empty($translation) && !is_numeric($translation); if (!$isBlank) { $this->translator()->setLocale($lang); $translation = $this->renderTemplate($translation); if ($translation !== null) { $templateString[$lang] = $translation; } } } $this->translator()->setLocale($origLang); $templateString->isRendered = true; return $templateString; } elseif (is_string($templateString)) { $isBlank = empty($templateString) && !is_numeric($templateString); if (!$isBlank) { return $this->renderTemplate($templateString); } } return ''; }
php
public function renderTranslatableTemplate($templateString) { if ($templateString instanceof Translation) { $origLang = $this->translator()->getLocale(); foreach ($this->translator()->availableLocales() as $lang) { if (!isset($templateString[$lang])) { continue; } $translation = $templateString[$lang]; $isBlank = empty($translation) && !is_numeric($translation); if (!$isBlank) { $this->translator()->setLocale($lang); $translation = $this->renderTemplate($translation); if ($translation !== null) { $templateString[$lang] = $translation; } } } $this->translator()->setLocale($origLang); $templateString->isRendered = true; return $templateString; } elseif (is_string($templateString)) { $isBlank = empty($templateString) && !is_numeric($templateString); if (!$isBlank) { return $this->renderTemplate($templateString); } } return ''; }
[ "public", "function", "renderTranslatableTemplate", "(", "$", "templateString", ")", "{", "if", "(", "$", "templateString", "instanceof", "Translation", ")", "{", "$", "origLang", "=", "$", "this", "->", "translator", "(", ")", "->", "getLocale", "(", ")", ";", "foreach", "(", "$", "this", "->", "translator", "(", ")", "->", "availableLocales", "(", ")", "as", "$", "lang", ")", "{", "if", "(", "!", "isset", "(", "$", "templateString", "[", "$", "lang", "]", ")", ")", "{", "continue", ";", "}", "$", "translation", "=", "$", "templateString", "[", "$", "lang", "]", ";", "$", "isBlank", "=", "empty", "(", "$", "translation", ")", "&&", "!", "is_numeric", "(", "$", "translation", ")", ";", "if", "(", "!", "$", "isBlank", ")", "{", "$", "this", "->", "translator", "(", ")", "->", "setLocale", "(", "$", "lang", ")", ";", "$", "translation", "=", "$", "this", "->", "renderTemplate", "(", "$", "translation", ")", ";", "if", "(", "$", "translation", "!==", "null", ")", "{", "$", "templateString", "[", "$", "lang", "]", "=", "$", "translation", ";", "}", "}", "}", "$", "this", "->", "translator", "(", ")", "->", "setLocale", "(", "$", "origLang", ")", ";", "$", "templateString", "->", "isRendered", "=", "true", ";", "return", "$", "templateString", ";", "}", "elseif", "(", "is_string", "(", "$", "templateString", ")", ")", "{", "$", "isBlank", "=", "empty", "(", "$", "templateString", ")", "&&", "!", "is_numeric", "(", "$", "templateString", ")", ";", "if", "(", "!", "$", "isBlank", ")", "{", "return", "$", "this", "->", "renderTemplate", "(", "$", "templateString", ")", ";", "}", "}", "return", "''", ";", "}" ]
Render the given template from string. @see \Charcoal\View\ViewableInterface::renderTemplate() @param mixed $templateString The template to render. @return string The rendered template.
[ "Render", "the", "given", "template", "from", "string", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractPropertyInput.php#L780-L810
train
acquia/commerce-manager
modules/acm_sku/src/Commands/AcmSkuDrushCommands.php
AcmSkuDrushCommands.syncProducts
public function syncProducts($langcode, $page_size, array $options = ['skus' => NULL, 'category_id' => NULL]) { $langcode = strtolower($langcode); $store_id = $this->i18nhelper->getStoreIdFromLangcode($langcode); if (empty($store_id)) { $this->output->writeln(dt("Store id not found for provided language code.")); return; } $page_size = (int) $page_size; if ($page_size <= 0) { $this->output->writeln(dt("Page size must be a positive integer.")); return; } $skus = $options['skus']; $category_id = $options['category_id']; // Apply only one filer at a time. if ($category_id) { $skus = ''; } // Ask for confirmation from user if attempt is to run full sync. if (empty($skus) && empty($category_id)) { $confirmation_text = dt('I CONFIRM'); $input = $this->io()->ask(dt('Are you sure you want to import all products for @language language? If yes, type: "@confirmation"', [ '@language' => $langcode, '@confirmation' => $confirmation_text, ])); if ($input != $confirmation_text) { throw new UserAbortException(dt('Please be more attentive in using this command and prove you are not sleep working...')); } } $this->output->writeln(dt('Requesting all commerce products for selected language code...')); $this->ingestApiWrapper->productFullSync($store_id, $langcode, $skus, $category_id, $page_size); $this->output->writeln(dt('Done.')); }
php
public function syncProducts($langcode, $page_size, array $options = ['skus' => NULL, 'category_id' => NULL]) { $langcode = strtolower($langcode); $store_id = $this->i18nhelper->getStoreIdFromLangcode($langcode); if (empty($store_id)) { $this->output->writeln(dt("Store id not found for provided language code.")); return; } $page_size = (int) $page_size; if ($page_size <= 0) { $this->output->writeln(dt("Page size must be a positive integer.")); return; } $skus = $options['skus']; $category_id = $options['category_id']; // Apply only one filer at a time. if ($category_id) { $skus = ''; } // Ask for confirmation from user if attempt is to run full sync. if (empty($skus) && empty($category_id)) { $confirmation_text = dt('I CONFIRM'); $input = $this->io()->ask(dt('Are you sure you want to import all products for @language language? If yes, type: "@confirmation"', [ '@language' => $langcode, '@confirmation' => $confirmation_text, ])); if ($input != $confirmation_text) { throw new UserAbortException(dt('Please be more attentive in using this command and prove you are not sleep working...')); } } $this->output->writeln(dt('Requesting all commerce products for selected language code...')); $this->ingestApiWrapper->productFullSync($store_id, $langcode, $skus, $category_id, $page_size); $this->output->writeln(dt('Done.')); }
[ "public", "function", "syncProducts", "(", "$", "langcode", ",", "$", "page_size", ",", "array", "$", "options", "=", "[", "'skus'", "=>", "NULL", ",", "'category_id'", "=>", "NULL", "]", ")", "{", "$", "langcode", "=", "strtolower", "(", "$", "langcode", ")", ";", "$", "store_id", "=", "$", "this", "->", "i18nhelper", "->", "getStoreIdFromLangcode", "(", "$", "langcode", ")", ";", "if", "(", "empty", "(", "$", "store_id", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "\"Store id not found for provided language code.\"", ")", ")", ";", "return", ";", "}", "$", "page_size", "=", "(", "int", ")", "$", "page_size", ";", "if", "(", "$", "page_size", "<=", "0", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "\"Page size must be a positive integer.\"", ")", ")", ";", "return", ";", "}", "$", "skus", "=", "$", "options", "[", "'skus'", "]", ";", "$", "category_id", "=", "$", "options", "[", "'category_id'", "]", ";", "// Apply only one filer at a time.", "if", "(", "$", "category_id", ")", "{", "$", "skus", "=", "''", ";", "}", "// Ask for confirmation from user if attempt is to run full sync.", "if", "(", "empty", "(", "$", "skus", ")", "&&", "empty", "(", "$", "category_id", ")", ")", "{", "$", "confirmation_text", "=", "dt", "(", "'I CONFIRM'", ")", ";", "$", "input", "=", "$", "this", "->", "io", "(", ")", "->", "ask", "(", "dt", "(", "'Are you sure you want to import all products for @language language? If yes, type: \"@confirmation\"'", ",", "[", "'@language'", "=>", "$", "langcode", ",", "'@confirmation'", "=>", "$", "confirmation_text", ",", "]", ")", ")", ";", "if", "(", "$", "input", "!=", "$", "confirmation_text", ")", "{", "throw", "new", "UserAbortException", "(", "dt", "(", "'Please be more attentive in using this command and prove you are not sleep working...'", ")", ")", ";", "}", "}", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Requesting all commerce products for selected language code...'", ")", ")", ";", "$", "this", "->", "ingestApiWrapper", "->", "productFullSync", "(", "$", "store_id", ",", "$", "langcode", ",", "$", "skus", ",", "$", "category_id", ",", "$", "page_size", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Done.'", ")", ")", ";", "}" ]
Run a full synchronization of all commerce product records. @param string $langcode Sync products available in this langcode. @param string $page_size Number of items to be synced in one batch. @param array $options Command options. @command acm_sku:sync-products @option skus SKUs to import (like query). @option category_id Magento category id to sync the products for. @validate-module-enabled acm_sku @aliases acsp,sync-commerce-products @usage drush acsp en 50 Run a full product synchronization of all available products in store linked to en and page size 50. @usage drush acsp en 50 --skus=\'M-H3495 130 2 FW\',\'M-H3496 130 004FW\',\'M-H3496 130 005FW\'' Synchronize sku data for the skus M-H3495 130 2 FW, M-H3496 130 004FW & M-H3496 130 005FW only in store linked to en and page size 50. @usage drush acsp en 50 --category_id=1234 Synchronize sku data for the skus in category with id 1234 only in store linked to en and page size 50. @throws \Drush\Exceptions\UserAbortException
[ "Run", "a", "full", "synchronization", "of", "all", "commerce", "product", "records", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Commands/AcmSkuDrushCommands.php#L250-L292
train
acquia/commerce-manager
modules/acm_sku/src/Commands/AcmSkuDrushCommands.php
AcmSkuDrushCommands.syncCategories
public function syncCategories() { $this->output->writeln(dt('Synchronizing all commerce categories, please wait...')); $response = $this->acmCategoryManager->synchronizeTree($this->categoryVid); // We trigger delete only if there is any term update/create. // So if API does not return anything, we don't delete all the categories. if (!empty($response['created']) || !empty($response['updated'])) { // Get all category terms with commerce id. $orphan_categories = $this->acmCategoryManager->getOrphanCategories($response); // If there are categories to delete. if (!empty($orphan_categories)) { // Show `tid + cat name + commerce id` for review. $this->io()->table([ dt('Category Id'), dt('Category Name'), dt('Category Commerce Id'), ], $orphan_categories); // Confirmation to delete old categories. if ($this->io()->confirm(dt('Are you sure you want to clean these old categories'), FALSE)) { // Allow other modules to skipping the deleting of terms. $this->moduleHandler->alter('acm_sku_sync_categories_delete', $orphan_categories); foreach ($orphan_categories as $tid => $rs) { $term = $this->entityTypeManager->getStorage('taxonomy_term')->load($tid); if ($term instanceof TermInterface) { // Delete the term. $term->delete(); } } } } } else { $this->logger->notice(dt('Not cleaning(deleting) old terms as there is no term update/create.')); } $this->output->writeln(dt('Done.')); }
php
public function syncCategories() { $this->output->writeln(dt('Synchronizing all commerce categories, please wait...')); $response = $this->acmCategoryManager->synchronizeTree($this->categoryVid); // We trigger delete only if there is any term update/create. // So if API does not return anything, we don't delete all the categories. if (!empty($response['created']) || !empty($response['updated'])) { // Get all category terms with commerce id. $orphan_categories = $this->acmCategoryManager->getOrphanCategories($response); // If there are categories to delete. if (!empty($orphan_categories)) { // Show `tid + cat name + commerce id` for review. $this->io()->table([ dt('Category Id'), dt('Category Name'), dt('Category Commerce Id'), ], $orphan_categories); // Confirmation to delete old categories. if ($this->io()->confirm(dt('Are you sure you want to clean these old categories'), FALSE)) { // Allow other modules to skipping the deleting of terms. $this->moduleHandler->alter('acm_sku_sync_categories_delete', $orphan_categories); foreach ($orphan_categories as $tid => $rs) { $term = $this->entityTypeManager->getStorage('taxonomy_term')->load($tid); if ($term instanceof TermInterface) { // Delete the term. $term->delete(); } } } } } else { $this->logger->notice(dt('Not cleaning(deleting) old terms as there is no term update/create.')); } $this->output->writeln(dt('Done.')); }
[ "public", "function", "syncCategories", "(", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Synchronizing all commerce categories, please wait...'", ")", ")", ";", "$", "response", "=", "$", "this", "->", "acmCategoryManager", "->", "synchronizeTree", "(", "$", "this", "->", "categoryVid", ")", ";", "// We trigger delete only if there is any term update/create.", "// So if API does not return anything, we don't delete all the categories.", "if", "(", "!", "empty", "(", "$", "response", "[", "'created'", "]", ")", "||", "!", "empty", "(", "$", "response", "[", "'updated'", "]", ")", ")", "{", "// Get all category terms with commerce id.", "$", "orphan_categories", "=", "$", "this", "->", "acmCategoryManager", "->", "getOrphanCategories", "(", "$", "response", ")", ";", "// If there are categories to delete.", "if", "(", "!", "empty", "(", "$", "orphan_categories", ")", ")", "{", "// Show `tid + cat name + commerce id` for review.", "$", "this", "->", "io", "(", ")", "->", "table", "(", "[", "dt", "(", "'Category Id'", ")", ",", "dt", "(", "'Category Name'", ")", ",", "dt", "(", "'Category Commerce Id'", ")", ",", "]", ",", "$", "orphan_categories", ")", ";", "// Confirmation to delete old categories.", "if", "(", "$", "this", "->", "io", "(", ")", "->", "confirm", "(", "dt", "(", "'Are you sure you want to clean these old categories'", ")", ",", "FALSE", ")", ")", "{", "// Allow other modules to skipping the deleting of terms.", "$", "this", "->", "moduleHandler", "->", "alter", "(", "'acm_sku_sync_categories_delete'", ",", "$", "orphan_categories", ")", ";", "foreach", "(", "$", "orphan_categories", "as", "$", "tid", "=>", "$", "rs", ")", "{", "$", "term", "=", "$", "this", "->", "entityTypeManager", "->", "getStorage", "(", "'taxonomy_term'", ")", "->", "load", "(", "$", "tid", ")", ";", "if", "(", "$", "term", "instanceof", "TermInterface", ")", "{", "// Delete the term.", "$", "term", "->", "delete", "(", ")", ";", "}", "}", "}", "}", "}", "else", "{", "$", "this", "->", "logger", "->", "notice", "(", "dt", "(", "'Not cleaning(deleting) old terms as there is no term update/create.'", ")", ")", ";", "}", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Done.'", ")", ")", ";", "}" ]
Run a full synchronization of all commerce product category records. @command acm_sku:sync-categories @validate-module-enabled acm_sku @aliases acsc,sync-commerce-cats @usage drush acsc Run a full category synchronization of all available categories.
[ "Run", "a", "full", "synchronization", "of", "all", "commerce", "product", "category", "records", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Commands/AcmSkuDrushCommands.php#L306-L346
train
acquia/commerce-manager
modules/acm_sku/src/Commands/AcmSkuDrushCommands.php
AcmSkuDrushCommands.syncProductOptions
public function syncProductOptions() { $this->logger->notice(dt('Synchronizing all commerce product options, please wait...')); $this->productOptionsManager->synchronizeProductOptions(); $this->logger->notice(dt('Product attribute sync completed.')); }
php
public function syncProductOptions() { $this->logger->notice(dt('Synchronizing all commerce product options, please wait...')); $this->productOptionsManager->synchronizeProductOptions(); $this->logger->notice(dt('Product attribute sync completed.')); }
[ "public", "function", "syncProductOptions", "(", ")", "{", "$", "this", "->", "logger", "->", "notice", "(", "dt", "(", "'Synchronizing all commerce product options, please wait...'", ")", ")", ";", "$", "this", "->", "productOptionsManager", "->", "synchronizeProductOptions", "(", ")", ";", "$", "this", "->", "logger", "->", "notice", "(", "dt", "(", "'Product attribute sync completed.'", ")", ")", ";", "}" ]
Run a full synchronization of all commerce product options. @command acm_sku:sync-product-options @validate-module-enabled acm_sku @aliases acspo,sync-commerce-product-options
[ "Run", "a", "full", "synchronization", "of", "all", "commerce", "product", "options", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Commands/AcmSkuDrushCommands.php#L357-L361
train
acquia/commerce-manager
modules/acm_sku/src/Commands/AcmSkuDrushCommands.php
AcmSkuDrushCommands.removeCategoryDuplicates
public function removeCategoryDuplicates() { $this->output->writeln(dt('Cleaning all commerce categories, please wait...')); $db = $this->connection; /** @var \Drupal\taxonomy\TermStorageInterface $termStorage */ $termStorage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); /** @var \Drupal\node\NodeStorageInterface $nodeStorage */ $nodeStorage = \Drupal::entityTypeManager()->getStorage('node'); $query = $db->select('taxonomy_term__field_commerce_id', 'ttfci'); $query->addField('ttfci', 'field_commerce_id_value', 'commerce_id'); $query->groupBy('commerce_id'); $query->having('count(*) > 1'); $result = $query->execute()->fetchAllKeyed(0, 0); if (empty($result)) { $this->output->writeln(dt('No duplicate categories found.')); return; } foreach ($result as $commerce_id) { $this->output->writeln(dt('Duplicate categories found for commerce id: @commerce_id.', [ '@commerce_id' => $commerce_id, ])); $query = $db->select('taxonomy_term__field_commerce_id', 'ttfci'); $query->addField('ttfci', 'entity_id', 'tid'); $query->condition('ttfci.field_commerce_id_value', $commerce_id); $query->orderBy('tid', 'DESC'); $tids = $query->execute()->fetchAllKeyed(0, 0); foreach ($tids as $tid) { $query = $nodeStorage->getQuery(); $query->condition('field_category', $tid); $nodes = $query->execute(); if (empty($nodes)) { $this->output->writeln(dt('No nodes found for tid: @tid for commerce id: @commerce_id. Deleting', [ '@commerce_id' => $commerce_id, '@tid' => $tid, ])); $term = $termStorage->load($tid); $term->delete(); unset($tids[$tid]); // Break the loop if only one left now, we might not have any products // added yet and categories are synced which means there will be no // nodes for any term. if (count($tids) == 1) { break; } } else { $this->output->writeln(dt('@count nodes found for tid: @tid for commerce id: @commerce_id. Not Deleting', [ '@commerce_id' => $commerce_id, '@tid' => $tid, '@count' => count($nodes), ])); } } } $this->output->writeln(dt('Done.')); }
php
public function removeCategoryDuplicates() { $this->output->writeln(dt('Cleaning all commerce categories, please wait...')); $db = $this->connection; /** @var \Drupal\taxonomy\TermStorageInterface $termStorage */ $termStorage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); /** @var \Drupal\node\NodeStorageInterface $nodeStorage */ $nodeStorage = \Drupal::entityTypeManager()->getStorage('node'); $query = $db->select('taxonomy_term__field_commerce_id', 'ttfci'); $query->addField('ttfci', 'field_commerce_id_value', 'commerce_id'); $query->groupBy('commerce_id'); $query->having('count(*) > 1'); $result = $query->execute()->fetchAllKeyed(0, 0); if (empty($result)) { $this->output->writeln(dt('No duplicate categories found.')); return; } foreach ($result as $commerce_id) { $this->output->writeln(dt('Duplicate categories found for commerce id: @commerce_id.', [ '@commerce_id' => $commerce_id, ])); $query = $db->select('taxonomy_term__field_commerce_id', 'ttfci'); $query->addField('ttfci', 'entity_id', 'tid'); $query->condition('ttfci.field_commerce_id_value', $commerce_id); $query->orderBy('tid', 'DESC'); $tids = $query->execute()->fetchAllKeyed(0, 0); foreach ($tids as $tid) { $query = $nodeStorage->getQuery(); $query->condition('field_category', $tid); $nodes = $query->execute(); if (empty($nodes)) { $this->output->writeln(dt('No nodes found for tid: @tid for commerce id: @commerce_id. Deleting', [ '@commerce_id' => $commerce_id, '@tid' => $tid, ])); $term = $termStorage->load($tid); $term->delete(); unset($tids[$tid]); // Break the loop if only one left now, we might not have any products // added yet and categories are synced which means there will be no // nodes for any term. if (count($tids) == 1) { break; } } else { $this->output->writeln(dt('@count nodes found for tid: @tid for commerce id: @commerce_id. Not Deleting', [ '@commerce_id' => $commerce_id, '@tid' => $tid, '@count' => count($nodes), ])); } } } $this->output->writeln(dt('Done.')); }
[ "public", "function", "removeCategoryDuplicates", "(", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Cleaning all commerce categories, please wait...'", ")", ")", ";", "$", "db", "=", "$", "this", "->", "connection", ";", "/** @var \\Drupal\\taxonomy\\TermStorageInterface $termStorage */", "$", "termStorage", "=", "\\", "Drupal", "::", "entityTypeManager", "(", ")", "->", "getStorage", "(", "'taxonomy_term'", ")", ";", "/** @var \\Drupal\\node\\NodeStorageInterface $nodeStorage */", "$", "nodeStorage", "=", "\\", "Drupal", "::", "entityTypeManager", "(", ")", "->", "getStorage", "(", "'node'", ")", ";", "$", "query", "=", "$", "db", "->", "select", "(", "'taxonomy_term__field_commerce_id'", ",", "'ttfci'", ")", ";", "$", "query", "->", "addField", "(", "'ttfci'", ",", "'field_commerce_id_value'", ",", "'commerce_id'", ")", ";", "$", "query", "->", "groupBy", "(", "'commerce_id'", ")", ";", "$", "query", "->", "having", "(", "'count(*) > 1'", ")", ";", "$", "result", "=", "$", "query", "->", "execute", "(", ")", "->", "fetchAllKeyed", "(", "0", ",", "0", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'No duplicate categories found.'", ")", ")", ";", "return", ";", "}", "foreach", "(", "$", "result", "as", "$", "commerce_id", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Duplicate categories found for commerce id: @commerce_id.'", ",", "[", "'@commerce_id'", "=>", "$", "commerce_id", ",", "]", ")", ")", ";", "$", "query", "=", "$", "db", "->", "select", "(", "'taxonomy_term__field_commerce_id'", ",", "'ttfci'", ")", ";", "$", "query", "->", "addField", "(", "'ttfci'", ",", "'entity_id'", ",", "'tid'", ")", ";", "$", "query", "->", "condition", "(", "'ttfci.field_commerce_id_value'", ",", "$", "commerce_id", ")", ";", "$", "query", "->", "orderBy", "(", "'tid'", ",", "'DESC'", ")", ";", "$", "tids", "=", "$", "query", "->", "execute", "(", ")", "->", "fetchAllKeyed", "(", "0", ",", "0", ")", ";", "foreach", "(", "$", "tids", "as", "$", "tid", ")", "{", "$", "query", "=", "$", "nodeStorage", "->", "getQuery", "(", ")", ";", "$", "query", "->", "condition", "(", "'field_category'", ",", "$", "tid", ")", ";", "$", "nodes", "=", "$", "query", "->", "execute", "(", ")", ";", "if", "(", "empty", "(", "$", "nodes", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'No nodes found for tid: @tid for commerce id: @commerce_id. Deleting'", ",", "[", "'@commerce_id'", "=>", "$", "commerce_id", ",", "'@tid'", "=>", "$", "tid", ",", "]", ")", ")", ";", "$", "term", "=", "$", "termStorage", "->", "load", "(", "$", "tid", ")", ";", "$", "term", "->", "delete", "(", ")", ";", "unset", "(", "$", "tids", "[", "$", "tid", "]", ")", ";", "// Break the loop if only one left now, we might not have any products", "// added yet and categories are synced which means there will be no", "// nodes for any term.", "if", "(", "count", "(", "$", "tids", ")", "==", "1", ")", "{", "break", ";", "}", "}", "else", "{", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'@count nodes found for tid: @tid for commerce id: @commerce_id. Not Deleting'", ",", "[", "'@commerce_id'", "=>", "$", "commerce_id", ",", "'@tid'", "=>", "$", "tid", ",", "'@count'", "=>", "count", "(", "$", "nodes", ")", ",", "]", ")", ")", ";", "}", "}", "}", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Done.'", ")", ")", ";", "}" ]
Remove all duplicate categories available in system. @command acm_sku:remove-category-duplicates @validate-module-enabled acm_sku @aliases acccrd,commerce-cats-remove-duplicates @usage drush acccrd Remove all duplicate categories available in system.
[ "Remove", "all", "duplicate", "categories", "available", "in", "system", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Commands/AcmSkuDrushCommands.php#L406-L473
train
acquia/commerce-manager
modules/acm_sku/src/Commands/AcmSkuDrushCommands.php
AcmSkuDrushCommands.flushSyncedData
public function flushSyncedData() { if (!$this->io()->confirm(dt("Are you sure you want to clean commerce data?"))) { throw new UserAbortException(); } $this->output->writeln(dt('Cleaning synced commerce data, please wait...')); // Set batch operation. $batch = [ 'title' => t('Clean synced data'), 'init_message' => t('Cleaning synced commerce data starting...'), 'operations' => [ ['\Drupal\acm_sku\Commands\AcmSkuDrushCommands::skuCleanProcess', []], ], 'progress_message' => t('Processed @current out of @total.'), 'error_message' => t('Synced data could not be cleaned because an error occurred.'), 'finished' => '_acm_sku_clean_finished', ]; batch_set($batch); drush_backend_batch_process(); $this->output->writeln(dt('Synced commerce data cleaned.')); }
php
public function flushSyncedData() { if (!$this->io()->confirm(dt("Are you sure you want to clean commerce data?"))) { throw new UserAbortException(); } $this->output->writeln(dt('Cleaning synced commerce data, please wait...')); // Set batch operation. $batch = [ 'title' => t('Clean synced data'), 'init_message' => t('Cleaning synced commerce data starting...'), 'operations' => [ ['\Drupal\acm_sku\Commands\AcmSkuDrushCommands::skuCleanProcess', []], ], 'progress_message' => t('Processed @current out of @total.'), 'error_message' => t('Synced data could not be cleaned because an error occurred.'), 'finished' => '_acm_sku_clean_finished', ]; batch_set($batch); drush_backend_batch_process(); $this->output->writeln(dt('Synced commerce data cleaned.')); }
[ "public", "function", "flushSyncedData", "(", ")", "{", "if", "(", "!", "$", "this", "->", "io", "(", ")", "->", "confirm", "(", "dt", "(", "\"Are you sure you want to clean commerce data?\"", ")", ")", ")", "{", "throw", "new", "UserAbortException", "(", ")", ";", "}", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Cleaning synced commerce data, please wait...'", ")", ")", ";", "// Set batch operation.", "$", "batch", "=", "[", "'title'", "=>", "t", "(", "'Clean synced data'", ")", ",", "'init_message'", "=>", "t", "(", "'Cleaning synced commerce data starting...'", ")", ",", "'operations'", "=>", "[", "[", "'\\Drupal\\acm_sku\\Commands\\AcmSkuDrushCommands::skuCleanProcess'", ",", "[", "]", "]", ",", "]", ",", "'progress_message'", "=>", "t", "(", "'Processed @current out of @total.'", ")", ",", "'error_message'", "=>", "t", "(", "'Synced data could not be cleaned because an error occurred.'", ")", ",", "'finished'", "=>", "'_acm_sku_clean_finished'", ",", "]", ";", "batch_set", "(", "$", "batch", ")", ";", "drush_backend_batch_process", "(", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Synced commerce data cleaned.'", ")", ")", ";", "}" ]
Flush all commerce data from the site. Handles Products, SKUs, Product Categories and Product Options and allows more data to be added for cleanup via alter hook. @command acm_sku:flush-synced-data @validate-module-enabled acm_sku @aliases accd,clean-synced-data @usage drush accd Flush all commerce data from the site (Products, SKUs, Product Categories and Product Options). @throws \Drush\Exceptions\UserAbortException
[ "Flush", "all", "commerce", "data", "from", "the", "site", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Commands/AcmSkuDrushCommands.php#L620-L641
train
acquia/commerce-manager
modules/acm_sku/src/Commands/AcmSkuDrushCommands.php
AcmSkuDrushCommands.flushLinkedSkuCache
public function flushLinkedSkuCache(array $options = ['sku' => NULL]) { // Check if we are asked to clear cache of specific SKU. if (!empty($options['sku'])) { if ($sku_entity = SKU::loadFromSku($options['sku'])) { $this->cacheTagsInvalidator->invalidateTags([ 'acm_sku:linked_skus:' . $sku_entity->id(), 'acm_sku:' . $sku_entity->id(), ]); $this->output->writeln(dt('Invalidated linked SKUs cache for @sku.', [ '@sku' => $options['sku'], ])); } return; } if (!$this->io()->confirm(dt('Are you sure you want to clear linked SKUs cache for all SKUs?'))) { throw new UserAbortException(); } $this->linkedSkuCache->deleteAll(); $this->output->writeln(dt('Cleared all linked SKUs cache.')); }
php
public function flushLinkedSkuCache(array $options = ['sku' => NULL]) { // Check if we are asked to clear cache of specific SKU. if (!empty($options['sku'])) { if ($sku_entity = SKU::loadFromSku($options['sku'])) { $this->cacheTagsInvalidator->invalidateTags([ 'acm_sku:linked_skus:' . $sku_entity->id(), 'acm_sku:' . $sku_entity->id(), ]); $this->output->writeln(dt('Invalidated linked SKUs cache for @sku.', [ '@sku' => $options['sku'], ])); } return; } if (!$this->io()->confirm(dt('Are you sure you want to clear linked SKUs cache for all SKUs?'))) { throw new UserAbortException(); } $this->linkedSkuCache->deleteAll(); $this->output->writeln(dt('Cleared all linked SKUs cache.')); }
[ "public", "function", "flushLinkedSkuCache", "(", "array", "$", "options", "=", "[", "'sku'", "=>", "NULL", "]", ")", "{", "// Check if we are asked to clear cache of specific SKU.", "if", "(", "!", "empty", "(", "$", "options", "[", "'sku'", "]", ")", ")", "{", "if", "(", "$", "sku_entity", "=", "SKU", "::", "loadFromSku", "(", "$", "options", "[", "'sku'", "]", ")", ")", "{", "$", "this", "->", "cacheTagsInvalidator", "->", "invalidateTags", "(", "[", "'acm_sku:linked_skus:'", ".", "$", "sku_entity", "->", "id", "(", ")", ",", "'acm_sku:'", ".", "$", "sku_entity", "->", "id", "(", ")", ",", "]", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Invalidated linked SKUs cache for @sku.'", ",", "[", "'@sku'", "=>", "$", "options", "[", "'sku'", "]", ",", "]", ")", ")", ";", "}", "return", ";", "}", "if", "(", "!", "$", "this", "->", "io", "(", ")", "->", "confirm", "(", "dt", "(", "'Are you sure you want to clear linked SKUs cache for all SKUs?'", ")", ")", ")", "{", "throw", "new", "UserAbortException", "(", ")", ";", "}", "$", "this", "->", "linkedSkuCache", "->", "deleteAll", "(", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "dt", "(", "'Cleared all linked SKUs cache.'", ")", ")", ";", "}" ]
Clear linked SKUs cache. @param array $options Command Options. @command acm_sku:clear-linked-skus-cache @option sku SKU to clean linked skus cache of. @validate-module-enabled acm_sku @aliases acclsc,clear-linked-skus-cache @usage drush acclsc Clear linked SKUs cache for all SKUs. @usage drush acclsc --skus=SKU Clear linked SKUs cache for particular SKU. @throws \Drush\Exceptions\UserAbortException
[ "Clear", "linked", "SKUs", "cache", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Commands/AcmSkuDrushCommands.php#L758-L782
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/QuickFormWidget.php
QuickFormWidget.formIdentFallback
public function formIdentFallback() { $metadata = $this->obj()->metadata(); if (isset($metadata['admin']['default_quick_form'])) { return $metadata['admin']['default_quick_form']; } if (isset($this->formData()['form_ident'])) { $ident = $this->formData()['form_ident']; if (is_string($ident) && !empty($ident)) { return $ident; } } return 'quick'; }
php
public function formIdentFallback() { $metadata = $this->obj()->metadata(); if (isset($metadata['admin']['default_quick_form'])) { return $metadata['admin']['default_quick_form']; } if (isset($this->formData()['form_ident'])) { $ident = $this->formData()['form_ident']; if (is_string($ident) && !empty($ident)) { return $ident; } } return 'quick'; }
[ "public", "function", "formIdentFallback", "(", ")", "{", "$", "metadata", "=", "$", "this", "->", "obj", "(", ")", "->", "metadata", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "'admin'", "]", "[", "'default_quick_form'", "]", ")", ")", "{", "return", "$", "metadata", "[", "'admin'", "]", "[", "'default_quick_form'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "formData", "(", ")", "[", "'form_ident'", "]", ")", ")", "{", "$", "ident", "=", "$", "this", "->", "formData", "(", ")", "[", "'form_ident'", "]", ";", "if", "(", "is_string", "(", "$", "ident", ")", "&&", "!", "empty", "(", "$", "ident", ")", ")", "{", "return", "$", "ident", ";", "}", "}", "return", "'quick'", ";", "}" ]
Retrieve the identifier of the form to use, or its fallback. @see ObjectFormWidget::formIdentFallback() @return string
[ "Retrieve", "the", "identifier", "of", "the", "form", "to", "use", "or", "its", "fallback", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/QuickFormWidget.php#L19-L36
train
acquia/commerce-manager
modules/acm/src/SessionStoreFactory.php
SessionStoreFactory.get
public static function get(ContainerInterface $container) { $storage_type = $container ->get('config.factory') ->get('acm.commerce_users') ->get('storage_type'); switch ($storage_type) { case 'database_store': $storage = $container ->get('acm.database_session_store') ->get('acm'); break; default: $storage = $container ->get('acm.php_session_store'); break; } return $storage; }
php
public static function get(ContainerInterface $container) { $storage_type = $container ->get('config.factory') ->get('acm.commerce_users') ->get('storage_type'); switch ($storage_type) { case 'database_store': $storage = $container ->get('acm.database_session_store') ->get('acm'); break; default: $storage = $container ->get('acm.php_session_store'); break; } return $storage; }
[ "public", "static", "function", "get", "(", "ContainerInterface", "$", "container", ")", "{", "$", "storage_type", "=", "$", "container", "->", "get", "(", "'config.factory'", ")", "->", "get", "(", "'acm.commerce_users'", ")", "->", "get", "(", "'storage_type'", ")", ";", "switch", "(", "$", "storage_type", ")", "{", "case", "'database_store'", ":", "$", "storage", "=", "$", "container", "->", "get", "(", "'acm.database_session_store'", ")", "->", "get", "(", "'acm'", ")", ";", "break", ";", "default", ":", "$", "storage", "=", "$", "container", "->", "get", "(", "'acm.php_session_store'", ")", ";", "break", ";", "}", "return", "$", "storage", ";", "}" ]
Creates a Storage object. @param \Symfony\Component\DependencyInjection\ContainerInterface $container The current service container. @return \Drupal\acm\SessionStoreInterface A storage object.
[ "Creates", "a", "Storage", "object", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/SessionStoreFactory.php#L21-L41
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Tinymce/UploadImageAction.php
UploadImageAction.run
public function run(RequestInterface $request, ResponseInterface $response) { $path = $request->getParam('upload_path'); if (!!$path) { $this->setUploadPath($path); } $this->uploadedPath = $this->fileUpload($_FILES['file']); $this->setSuccess(!!$this->uploadedPath); return $response; }
php
public function run(RequestInterface $request, ResponseInterface $response) { $path = $request->getParam('upload_path'); if (!!$path) { $this->setUploadPath($path); } $this->uploadedPath = $this->fileUpload($_FILES['file']); $this->setSuccess(!!$this->uploadedPath); return $response; }
[ "public", "function", "run", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getParam", "(", "'upload_path'", ")", ";", "if", "(", "!", "!", "$", "path", ")", "{", "$", "this", "->", "setUploadPath", "(", "$", "path", ")", ";", "}", "$", "this", "->", "uploadedPath", "=", "$", "this", "->", "fileUpload", "(", "$", "_FILES", "[", "'file'", "]", ")", ";", "$", "this", "->", "setSuccess", "(", "!", "!", "$", "this", "->", "uploadedPath", ")", ";", "return", "$", "response", ";", "}" ]
Gets a psr7 request and response and returns a response. Called from `__invoke()` as the first thing. @param RequestInterface $request A PSR-7 compatible Request instance. @param ResponseInterface $response A PSR-7 compatible Response instance. @return ResponseInterface
[ "Gets", "a", "psr7", "request", "and", "response", "and", "returns", "a", "response", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Tinymce/UploadImageAction.php#L83-L96
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Tinymce/UploadImageAction.php
UploadImageAction.isAbsolutePath
protected function isAbsolutePath($file) { return strspn($file, '/\\', 0, 1) || (strlen($file) > 3 && ctype_alpha($file[0]) && substr($file, 1, 1) === ':' && strspn($file, '/\\', 2, 1)) || null !== parse_url($file, PHP_URL_SCHEME); }
php
protected function isAbsolutePath($file) { return strspn($file, '/\\', 0, 1) || (strlen($file) > 3 && ctype_alpha($file[0]) && substr($file, 1, 1) === ':' && strspn($file, '/\\', 2, 1)) || null !== parse_url($file, PHP_URL_SCHEME); }
[ "protected", "function", "isAbsolutePath", "(", "$", "file", ")", "{", "return", "strspn", "(", "$", "file", ",", "'/\\\\'", ",", "0", ",", "1", ")", "||", "(", "strlen", "(", "$", "file", ")", ">", "3", "&&", "ctype_alpha", "(", "$", "file", "[", "0", "]", ")", "&&", "substr", "(", "$", "file", ",", "1", ",", "1", ")", "===", "':'", "&&", "strspn", "(", "$", "file", ",", "'/\\\\'", ",", "2", ",", "1", ")", ")", "||", "null", "!==", "parse_url", "(", "$", "file", ",", "PHP_URL_SCHEME", ")", ";", "}" ]
Determine if the given file path is am absolute path. Note: Adapted from symfony\filesystem. @see https://github.com/symfony/symfony/blob/v3.2.2/LICENSE @param string $file A file path. @return boolean Returns TRUE if the given path is absolute. Otherwise, returns FALSE.
[ "Determine", "if", "the", "given", "file", "path", "is", "am", "absolute", "path", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Tinymce/UploadImageAction.php#L219-L227
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Tinymce/UploadImageAction.php
UploadImageAction.sanitizeFilename
public function sanitizeFilename($filename) { // Remove blacklisted caharacters $blacklist = ['/', '\\', '\0', '*', ':', '?', '"', '<', '>', '|', '#', '&', '!', '`', ' ']; $filename = str_replace($blacklist, '_', $filename); // Avoid hidden file $filename = ltrim($filename, '.'); return $filename; }
php
public function sanitizeFilename($filename) { // Remove blacklisted caharacters $blacklist = ['/', '\\', '\0', '*', ':', '?', '"', '<', '>', '|', '#', '&', '!', '`', ' ']; $filename = str_replace($blacklist, '_', $filename); // Avoid hidden file $filename = ltrim($filename, '.'); return $filename; }
[ "public", "function", "sanitizeFilename", "(", "$", "filename", ")", "{", "// Remove blacklisted caharacters", "$", "blacklist", "=", "[", "'/'", ",", "'\\\\'", ",", "'\\0'", ",", "'*'", ",", "':'", ",", "'?'", ",", "'\"'", ",", "'<'", ",", "'>'", ",", "'|'", ",", "'#'", ",", "'&'", ",", "'!'", ",", "'`'", ",", "' '", "]", ";", "$", "filename", "=", "str_replace", "(", "$", "blacklist", ",", "'_'", ",", "$", "filename", ")", ";", "// Avoid hidden file", "$", "filename", "=", "ltrim", "(", "$", "filename", ",", "'.'", ")", ";", "return", "$", "filename", ";", "}" ]
Sanitize a filename by removing characters from a blacklist and escaping dot. @param string $filename The filename to sanitize. @return string The sanitized filename.
[ "Sanitize", "a", "filename", "by", "removing", "characters", "from", "a", "blacklist", "and", "escaping", "dot", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Tinymce/UploadImageAction.php#L235-L245
train
dazzle-php/ssh
src/SSH/SSH2.php
SSH2.createConnection
protected function createConnection($host, $port, $methods, $callbacks) { return @ssh2_connect($host, $port, $methods, $callbacks); }
php
protected function createConnection($host, $port, $methods, $callbacks) { return @ssh2_connect($host, $port, $methods, $callbacks); }
[ "protected", "function", "createConnection", "(", "$", "host", ",", "$", "port", ",", "$", "methods", ",", "$", "callbacks", ")", "{", "return", "@", "ssh2_connect", "(", "$", "host", ",", "$", "port", ",", "$", "methods", ",", "$", "callbacks", ")", ";", "}" ]
Create SSH2 connection. @param string $host @param int $port @param mixed[] $methods @param callable[] $callbacks @return resource
[ "Create", "SSH2", "connection", "." ]
8e48867f7b147a7b27bd4e995ac42e6df65c17bb
https://github.com/dazzle-php/ssh/blob/8e48867f7b147a7b27bd4e995ac42e6df65c17bb/src/SSH/SSH2.php#L238-L241
train
acquia/commerce-manager
modules/acm_sku/src/Form/ProductSyncForm.php
ProductSyncForm.buildForm
public function buildForm(array $form, FormStateInterface $form_state) { $form['actions']['#type'] = 'actions'; if ($category_vid = $this->connectorConfig->get('category_vid')) { $form['actions']['cats'] = [ '#type' => 'submit', '#value' => t('Synchronize Categories'), ]; } $form['actions']['products_async'] = [ '#type' => 'submit', '#value' => t('Synchronize Products (async)'), ]; $form['actions']['products_sync'] = [ '#type' => 'submit', '#value' => t('Synchronize Products (sync)'), ]; return ($form); }
php
public function buildForm(array $form, FormStateInterface $form_state) { $form['actions']['#type'] = 'actions'; if ($category_vid = $this->connectorConfig->get('category_vid')) { $form['actions']['cats'] = [ '#type' => 'submit', '#value' => t('Synchronize Categories'), ]; } $form['actions']['products_async'] = [ '#type' => 'submit', '#value' => t('Synchronize Products (async)'), ]; $form['actions']['products_sync'] = [ '#type' => 'submit', '#value' => t('Synchronize Products (sync)'), ]; return ($form); }
[ "public", "function", "buildForm", "(", "array", "$", "form", ",", "FormStateInterface", "$", "form_state", ")", "{", "$", "form", "[", "'actions'", "]", "[", "'#type'", "]", "=", "'actions'", ";", "if", "(", "$", "category_vid", "=", "$", "this", "->", "connectorConfig", "->", "get", "(", "'category_vid'", ")", ")", "{", "$", "form", "[", "'actions'", "]", "[", "'cats'", "]", "=", "[", "'#type'", "=>", "'submit'", ",", "'#value'", "=>", "t", "(", "'Synchronize Categories'", ")", ",", "]", ";", "}", "$", "form", "[", "'actions'", "]", "[", "'products_async'", "]", "=", "[", "'#type'", "=>", "'submit'", ",", "'#value'", "=>", "t", "(", "'Synchronize Products (async)'", ")", ",", "]", ";", "$", "form", "[", "'actions'", "]", "[", "'products_sync'", "]", "=", "[", "'#type'", "=>", "'submit'", ",", "'#value'", "=>", "t", "(", "'Synchronize Products (sync)'", ")", ",", "]", ";", "return", "(", "$", "form", ")", ";", "}" ]
Define the form used for settings. @param array $form An associative array containing the structure of the form. @param \Drupal\Core\Form\FormStateInterface $form_state An associative array containing the current state of the form. @return array Form definition array.
[ "Define", "the", "form", "used", "for", "settings", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Form/ProductSyncForm.php#L126-L147
train
acquia/commerce-manager
modules/acm_customer/src/Plugin/CustomerForm/Orders.php
Orders.buildSummary
public function buildSummary(array $orders = []) { if (empty($orders)) { return [ '#markup' => $this->t('You have no orders'), ]; } $build = []; foreach ($orders as $order) { $build[] = [ '#theme' => 'user_order', '#order' => $order, '#order_details_path' => Url::fromRoute('acm_customer.view_page', [ 'page' => $this->getPageId(), 'action' => 'edit', 'id' => $order['order_id'], ])->toString(), ]; } return $build; }
php
public function buildSummary(array $orders = []) { if (empty($orders)) { return [ '#markup' => $this->t('You have no orders'), ]; } $build = []; foreach ($orders as $order) { $build[] = [ '#theme' => 'user_order', '#order' => $order, '#order_details_path' => Url::fromRoute('acm_customer.view_page', [ 'page' => $this->getPageId(), 'action' => 'edit', 'id' => $order['order_id'], ])->toString(), ]; } return $build; }
[ "public", "function", "buildSummary", "(", "array", "$", "orders", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "orders", ")", ")", "{", "return", "[", "'#markup'", "=>", "$", "this", "->", "t", "(", "'You have no orders'", ")", ",", "]", ";", "}", "$", "build", "=", "[", "]", ";", "foreach", "(", "$", "orders", "as", "$", "order", ")", "{", "$", "build", "[", "]", "=", "[", "'#theme'", "=>", "'user_order'", ",", "'#order'", "=>", "$", "order", ",", "'#order_details_path'", "=>", "Url", "::", "fromRoute", "(", "'acm_customer.view_page'", ",", "[", "'page'", "=>", "$", "this", "->", "getPageId", "(", ")", ",", "'action'", "=>", "'edit'", ",", "'id'", "=>", "$", "order", "[", "'order_id'", "]", ",", "]", ")", "->", "toString", "(", ")", ",", "]", ";", "}", "return", "$", "build", ";", "}" ]
Builds a summary of orders. @param array $orders The orders to build a summary for. @return array An render array.
[ "Builds", "a", "summary", "of", "orders", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Plugin/CustomerForm/Orders.php#L37-L59
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Account/ResetPasswordAction.php
ResetPasswordAction.deleteToken
private function deleteToken($token) { $obj = $this->modelFactory()->create(LostPasswordToken::class); $obj->setToken($token); $obj->delete(); }
php
private function deleteToken($token) { $obj = $this->modelFactory()->create(LostPasswordToken::class); $obj->setToken($token); $obj->delete(); }
[ "private", "function", "deleteToken", "(", "$", "token", ")", "{", "$", "obj", "=", "$", "this", "->", "modelFactory", "(", ")", "->", "create", "(", "LostPasswordToken", "::", "class", ")", ";", "$", "obj", "->", "setToken", "(", "$", "token", ")", ";", "$", "obj", "->", "delete", "(", ")", ";", "}" ]
Delete the given password reset token. @param string $token The token to delete. @return void
[ "Delete", "the", "given", "password", "reset", "token", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Account/ResetPasswordAction.php#L238-L243
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/DocWidget.php
DocWidget.setDisplayOptions
public function setDisplayOptions(array $options) { if (!is_array($options)) { throw new \RuntimeException('The display options must be an associative array.'); } $this->displayOptions = array_merge($this->defaultDisplayOptions(), $options); return $this; }
php
public function setDisplayOptions(array $options) { if (!is_array($options)) { throw new \RuntimeException('The display options must be an associative array.'); } $this->displayOptions = array_merge($this->defaultDisplayOptions(), $options); return $this; }
[ "public", "function", "setDisplayOptions", "(", "array", "$", "options", ")", "{", "if", "(", "!", "is_array", "(", "$", "options", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'The display options must be an associative array.'", ")", ";", "}", "$", "this", "->", "displayOptions", "=", "array_merge", "(", "$", "this", "->", "defaultDisplayOptions", "(", ")", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Set the display options for the widget. @param array $options Display configuration. @throws \RuntimeException If the display options are not an associative array. @return self
[ "Set", "the", "display", "options", "for", "the", "widget", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/DocWidget.php#L221-L230
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/DocWidget.php
DocWidget.setFormData
public function setFormData(array $data) { $objData = $this->objData(); $merged = array_replace_recursive($objData, $data); // Remove null values $merged = array_filter($merged, function ($val) { if ($val === null) { return false; } return true; }); $this->formData = $merged; $this->obj()->setData($merged); return $this; }
php
public function setFormData(array $data) { $objData = $this->objData(); $merged = array_replace_recursive($objData, $data); // Remove null values $merged = array_filter($merged, function ($val) { if ($val === null) { return false; } return true; }); $this->formData = $merged; $this->obj()->setData($merged); return $this; }
[ "public", "function", "setFormData", "(", "array", "$", "data", ")", "{", "$", "objData", "=", "$", "this", "->", "objData", "(", ")", ";", "$", "merged", "=", "array_replace_recursive", "(", "$", "objData", ",", "$", "data", ")", ";", "// Remove null values", "$", "merged", "=", "array_filter", "(", "$", "merged", ",", "function", "(", "$", "val", ")", "{", "if", "(", "$", "val", "===", "null", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", ")", ";", "$", "this", "->", "formData", "=", "$", "merged", ";", "$", "this", "->", "obj", "(", ")", "->", "setData", "(", "$", "merged", ")", ";", "return", "$", "this", ";", "}" ]
Set the form's auxiliary data. This method is called via {@see self::setData()} if a "form_data" parameter is present on the HTTP request. @param array $data Data. @return ObjectFormWidget Chainable.
[ "Set", "the", "form", "s", "auxiliary", "data", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/DocWidget.php#L408-L426
train
acquia/commerce-manager
modules/acm_cart/src/CartStorage.php
CartStorage.getCartSkus
public function getCartSkus() { $items = $this->items(); if (empty($items)) { return []; } $skus = []; foreach ($items as $item) { $skus[] = $item['sku']; } return $skus; }
php
public function getCartSkus() { $items = $this->items(); if (empty($items)) { return []; } $skus = []; foreach ($items as $item) { $skus[] = $item['sku']; } return $skus; }
[ "public", "function", "getCartSkus", "(", ")", "{", "$", "items", "=", "$", "this", "->", "items", "(", ")", ";", "if", "(", "empty", "(", "$", "items", ")", ")", "{", "return", "[", "]", ";", "}", "$", "skus", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "skus", "[", "]", "=", "$", "item", "[", "'sku'", "]", ";", "}", "return", "$", "skus", ";", "}" ]
Get skus of current cart items. @return array Items in the current cart.
[ "Get", "skus", "of", "current", "cart", "items", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/CartStorage.php#L245-L257
train
acquia/commerce-manager
modules/acm_cart/src/CartStorage.php
CartStorage.pushCart
public function pushCart() { $cart = $this->cart; if (!$cart) { return; } // Cart exists, derive update array and update cookie. $this->setCookie('acm_cart_id', $cart->id()); $update = $cart->getCart(); $cart_event = $this->eventDispatcher->dispatch(Events::PUSH_CART, new CartPushEvent($update)); $cart_response = (object) $this->apiWrapper->updateCart($cart->id(), $cart_event->getRawCart()); if (empty($cart_response)) { return; } return $cart; }
php
public function pushCart() { $cart = $this->cart; if (!$cart) { return; } // Cart exists, derive update array and update cookie. $this->setCookie('acm_cart_id', $cart->id()); $update = $cart->getCart(); $cart_event = $this->eventDispatcher->dispatch(Events::PUSH_CART, new CartPushEvent($update)); $cart_response = (object) $this->apiWrapper->updateCart($cart->id(), $cart_event->getRawCart()); if (empty($cart_response)) { return; } return $cart; }
[ "public", "function", "pushCart", "(", ")", "{", "$", "cart", "=", "$", "this", "->", "cart", ";", "if", "(", "!", "$", "cart", ")", "{", "return", ";", "}", "// Cart exists, derive update array and update cookie.", "$", "this", "->", "setCookie", "(", "'acm_cart_id'", ",", "$", "cart", "->", "id", "(", ")", ")", ";", "$", "update", "=", "$", "cart", "->", "getCart", "(", ")", ";", "$", "cart_event", "=", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "Events", "::", "PUSH_CART", ",", "new", "CartPushEvent", "(", "$", "update", ")", ")", ";", "$", "cart_response", "=", "(", "object", ")", "$", "this", "->", "apiWrapper", "->", "updateCart", "(", "$", "cart", "->", "id", "(", ")", ",", "$", "cart_event", "->", "getRawCart", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "cart_response", ")", ")", "{", "return", ";", "}", "return", "$", "cart", ";", "}" ]
Pushes the cart to the ecommerce app via the Connector API. @deprecated Use updateCart() instead. @return null|\Drupal\acm_cart\CartInterface Returns the cart data as sent by the ecommerce backend
[ "Pushes", "the", "cart", "to", "the", "ecommerce", "app", "via", "the", "Connector", "API", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/CartStorage.php#L328-L346
train
acquia/commerce-manager
modules/acm_cart/src/CartStorage.php
CartStorage.clearCartItemsStockCache
public function clearCartItemsStockCache() { $items = $this->items(); if (empty($items)) { return; } foreach ($items as $item) { $sku_entity = SKU::loadFromSku($item['sku']); $sku_entity->refreshStock(); } }
php
public function clearCartItemsStockCache() { $items = $this->items(); if (empty($items)) { return; } foreach ($items as $item) { $sku_entity = SKU::loadFromSku($item['sku']); $sku_entity->refreshStock(); } }
[ "public", "function", "clearCartItemsStockCache", "(", ")", "{", "$", "items", "=", "$", "this", "->", "items", "(", ")", ";", "if", "(", "empty", "(", "$", "items", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "sku_entity", "=", "SKU", "::", "loadFromSku", "(", "$", "item", "[", "'sku'", "]", ")", ";", "$", "sku_entity", "->", "refreshStock", "(", ")", ";", "}", "}" ]
Helper function to clear stock cache of all items in cart.
[ "Helper", "function", "to", "clear", "stock", "cache", "of", "all", "items", "in", "cart", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/CartStorage.php#L430-L441
train
acquia/commerce-manager
modules/acm_cart/src/CartStorage.php
CartStorage.getCustomerId
protected function getCustomerId() { $customer_id = NULL; $current_user = $this->getCurrentUser(); if ($current_user->isAnonymous()) { return $customer_id; } $use_ecomm_sessions = \Drupal::config('acm.commerce_users') ->get('use_ecomm_sessions'); if ($use_ecomm_sessions) { $customer_id = $current_user->getAccount()->id(); } else { $customer_id = $current_user->getAccount()->acm_customer_id; } return $customer_id; }
php
protected function getCustomerId() { $customer_id = NULL; $current_user = $this->getCurrentUser(); if ($current_user->isAnonymous()) { return $customer_id; } $use_ecomm_sessions = \Drupal::config('acm.commerce_users') ->get('use_ecomm_sessions'); if ($use_ecomm_sessions) { $customer_id = $current_user->getAccount()->id(); } else { $customer_id = $current_user->getAccount()->acm_customer_id; } return $customer_id; }
[ "protected", "function", "getCustomerId", "(", ")", "{", "$", "customer_id", "=", "NULL", ";", "$", "current_user", "=", "$", "this", "->", "getCurrentUser", "(", ")", ";", "if", "(", "$", "current_user", "->", "isAnonymous", "(", ")", ")", "{", "return", "$", "customer_id", ";", "}", "$", "use_ecomm_sessions", "=", "\\", "Drupal", "::", "config", "(", "'acm.commerce_users'", ")", "->", "get", "(", "'use_ecomm_sessions'", ")", ";", "if", "(", "$", "use_ecomm_sessions", ")", "{", "$", "customer_id", "=", "$", "current_user", "->", "getAccount", "(", ")", "->", "id", "(", ")", ";", "}", "else", "{", "$", "customer_id", "=", "$", "current_user", "->", "getAccount", "(", ")", "->", "acm_customer_id", ";", "}", "return", "$", "customer_id", ";", "}" ]
Gets the current customer user id. @return null|int|string The current customer id. NULL for none, int for Magento, string for Hybris.
[ "Gets", "the", "current", "customer", "user", "id", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/CartStorage.php#L478-L497
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/FileInput.php
FileInput.previewVal
public function previewVal() { $val = parent::inputVal(); if (empty($val)) { return ''; } $parts = parse_url($val); if (empty($parts['scheme']) && !in_array($val[0], [ '/', '#', '?' ])) { $path = isset($parts['path']) ? ltrim($parts['path'], '/') : ''; $query = isset($parts['query']) ? $parts['query'] : ''; $hash = isset($parts['fragment']) ? $parts['fragment'] : ''; $val = $this->baseUrl->withPath($path)->withQuery($query)->withFragment($hash); } return $val; }
php
public function previewVal() { $val = parent::inputVal(); if (empty($val)) { return ''; } $parts = parse_url($val); if (empty($parts['scheme']) && !in_array($val[0], [ '/', '#', '?' ])) { $path = isset($parts['path']) ? ltrim($parts['path'], '/') : ''; $query = isset($parts['query']) ? $parts['query'] : ''; $hash = isset($parts['fragment']) ? $parts['fragment'] : ''; $val = $this->baseUrl->withPath($path)->withQuery($query)->withFragment($hash); } return $val; }
[ "public", "function", "previewVal", "(", ")", "{", "$", "val", "=", "parent", "::", "inputVal", "(", ")", ";", "if", "(", "empty", "(", "$", "val", ")", ")", "{", "return", "''", ";", "}", "$", "parts", "=", "parse_url", "(", "$", "val", ")", ";", "if", "(", "empty", "(", "$", "parts", "[", "'scheme'", "]", ")", "&&", "!", "in_array", "(", "$", "val", "[", "0", "]", ",", "[", "'/'", ",", "'#'", ",", "'?'", "]", ")", ")", "{", "$", "path", "=", "isset", "(", "$", "parts", "[", "'path'", "]", ")", "?", "ltrim", "(", "$", "parts", "[", "'path'", "]", ",", "'/'", ")", ":", "''", ";", "$", "query", "=", "isset", "(", "$", "parts", "[", "'query'", "]", ")", "?", "$", "parts", "[", "'query'", "]", ":", "''", ";", "$", "hash", "=", "isset", "(", "$", "parts", "[", "'fragment'", "]", ")", "?", "$", "parts", "[", "'fragment'", "]", ":", "''", ";", "$", "val", "=", "$", "this", "->", "baseUrl", "->", "withPath", "(", "$", "path", ")", "->", "withQuery", "(", "$", "query", ")", "->", "withFragment", "(", "$", "hash", ")", ";", "}", "return", "$", "val", ";", "}" ]
Retrieve input value for file preview. @return string
[ "Retrieve", "input", "value", "for", "file", "preview", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/FileInput.php#L138-L154
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/FileInput.php
FileInput.dialogTitle
public function dialogTitle() { if ($this->dialogTitle === null) { $this->setDialogTitle($this->defaultDialogTitle()); } return $this->dialogTitle; }
php
public function dialogTitle() { if ($this->dialogTitle === null) { $this->setDialogTitle($this->defaultDialogTitle()); } return $this->dialogTitle; }
[ "public", "function", "dialogTitle", "(", ")", "{", "if", "(", "$", "this", "->", "dialogTitle", "===", "null", ")", "{", "$", "this", "->", "setDialogTitle", "(", "$", "this", "->", "defaultDialogTitle", "(", ")", ")", ";", "}", "return", "$", "this", "->", "dialogTitle", ";", "}" ]
Retrieve the title for the file picker dialog. @return \Charcoal\Translator\Translation|string|null
[ "Retrieve", "the", "title", "for", "the", "file", "picker", "dialog", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/FileInput.php#L239-L246
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/FileInput.php
FileInput.chooseButtonLabel
public function chooseButtonLabel() { if ($this->chooseButtonLabel === null) { $this->setChooseButtonLabel($this->defaultChooseButtonLabel()); } return $this->chooseButtonLabel; }
php
public function chooseButtonLabel() { if ($this->chooseButtonLabel === null) { $this->setChooseButtonLabel($this->defaultChooseButtonLabel()); } return $this->chooseButtonLabel; }
[ "public", "function", "chooseButtonLabel", "(", ")", "{", "if", "(", "$", "this", "->", "chooseButtonLabel", "===", "null", ")", "{", "$", "this", "->", "setChooseButtonLabel", "(", "$", "this", "->", "defaultChooseButtonLabel", "(", ")", ")", ";", "}", "return", "$", "this", "->", "chooseButtonLabel", ";", "}" ]
Retrieve the label for the file picker button. @return \Charcoal\Translator\Translation|string|null
[ "Retrieve", "the", "label", "for", "the", "file", "picker", "button", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/FileInput.php#L268-L275
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/FileInput.php
FileInput.removeButtonLabel
public function removeButtonLabel() { if ($this->removeButtonLabel === null) { $this->setRemoveButtonLabel($this->defaultRemoveButtonLabel()); } return $this->removeButtonLabel; }
php
public function removeButtonLabel() { if ($this->removeButtonLabel === null) { $this->setRemoveButtonLabel($this->defaultRemoveButtonLabel()); } return $this->removeButtonLabel; }
[ "public", "function", "removeButtonLabel", "(", ")", "{", "if", "(", "$", "this", "->", "removeButtonLabel", "===", "null", ")", "{", "$", "this", "->", "setRemoveButtonLabel", "(", "$", "this", "->", "defaultRemoveButtonLabel", "(", ")", ")", ";", "}", "return", "$", "this", "->", "removeButtonLabel", ";", "}" ]
Retrieve the label for the file removal button. @return \Charcoal\Translator\Translation|string|null
[ "Retrieve", "the", "label", "for", "the", "file", "removal", "button", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/FileInput.php#L296-L303
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/ImageInput.php
ImageInput.setClassAttr
public function setClassAttr($classes) { if (is_array($classes)) { $classes = implode(' ', $classes); } $this->classAttr = $classes; return $this; }
php
public function setClassAttr($classes) { if (is_array($classes)) { $classes = implode(' ', $classes); } $this->classAttr = $classes; return $this; }
[ "public", "function", "setClassAttr", "(", "$", "classes", ")", "{", "if", "(", "is_array", "(", "$", "classes", ")", ")", "{", "$", "classes", "=", "implode", "(", "' '", ",", "$", "classes", ")", ";", "}", "$", "this", "->", "classAttr", "=", "$", "classes", ";", "return", "$", "this", ";", "}" ]
Set the CSS classes to apply on the image. @param string|string[] $classes A space-separated list of CSS classes. @return ImageDisplay Chainable
[ "Set", "the", "CSS", "classes", "to", "apply", "on", "the", "image", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/ImageInput.php#L58-L67
train
acquia/commerce-manager
modules/acm/src/Routing/CommerceUserRoutes.php
CommerceUserRoutes.routes
public function routes() { $routes = []; // Only add the routes if we're using ecomm sessions, otherwise drupal user // accounts will be created for everyone and the core user login/logout // functionality can be used. if (!$this->config->get('use_ecomm_sessions')) { return $routes; } $external_registration_path = $this->config->get('external_registration_path') ?: '/register'; $external_login_path = $this->config->get('external_login_path') ?: '/login'; $external_logout_path = $this->config->get('external_logout_path') ?: '/logout'; if ($this->config->get('use_ecomm_pass_reset')) { $ecomm_forgot_password_path = $this->config->get('ecomm_forgot_password_path') ?: '/forgottenpassword'; $routes['acm.ecomm_password_reset'] = new Route( $ecomm_forgot_password_path, [ '_form' => 'Drupal\acm\Form\CommerceUserPasswordTokenResetForm', '_title' => 'Reset Password', ], [ // Authentication status will be checked within the form. '_access' => 'TRUE', ], [ 'no_cache' => 'TRUE', ] ); } $routes['acm.external_user_registration'] = new Route( $external_registration_path, [ '_form' => 'Drupal\acm\Form\CommerceUserRegistrationForm', '_title' => 'Create Account', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_login'] = new Route( $external_login_path, [ '_form' => 'Drupal\acm\Form\CommerceUserLoginForm', '_title' => 'Log In', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_logout'] = new Route( $external_logout_path, [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::logout', ], [ '_commerce_user_is_logged_in' => 'TRUE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password'] = new Route( '/commerce-user/password', [ '_form' => 'Drupal\acm\Form\CommerceUserPasswordForm', '_title' => 'Reset your password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password_reset'] = new Route( '/commerce-user/reset/{email}/{timestamp}/{hash}', [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::resetPass', '_title' => 'Reset password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password_reset_form'] = new Route( '/commerce-user/reset/{email}', [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::getResetPassForm', '_title' => 'Reset password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password_reset_login'] = new Route( '/commerce-user/reset/{email}/{timestamp}/{hash}/login', [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::resetPassLogin', '_title' => 'Reset password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); return $routes; }
php
public function routes() { $routes = []; // Only add the routes if we're using ecomm sessions, otherwise drupal user // accounts will be created for everyone and the core user login/logout // functionality can be used. if (!$this->config->get('use_ecomm_sessions')) { return $routes; } $external_registration_path = $this->config->get('external_registration_path') ?: '/register'; $external_login_path = $this->config->get('external_login_path') ?: '/login'; $external_logout_path = $this->config->get('external_logout_path') ?: '/logout'; if ($this->config->get('use_ecomm_pass_reset')) { $ecomm_forgot_password_path = $this->config->get('ecomm_forgot_password_path') ?: '/forgottenpassword'; $routes['acm.ecomm_password_reset'] = new Route( $ecomm_forgot_password_path, [ '_form' => 'Drupal\acm\Form\CommerceUserPasswordTokenResetForm', '_title' => 'Reset Password', ], [ // Authentication status will be checked within the form. '_access' => 'TRUE', ], [ 'no_cache' => 'TRUE', ] ); } $routes['acm.external_user_registration'] = new Route( $external_registration_path, [ '_form' => 'Drupal\acm\Form\CommerceUserRegistrationForm', '_title' => 'Create Account', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_login'] = new Route( $external_login_path, [ '_form' => 'Drupal\acm\Form\CommerceUserLoginForm', '_title' => 'Log In', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_logout'] = new Route( $external_logout_path, [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::logout', ], [ '_commerce_user_is_logged_in' => 'TRUE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password'] = new Route( '/commerce-user/password', [ '_form' => 'Drupal\acm\Form\CommerceUserPasswordForm', '_title' => 'Reset your password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password_reset'] = new Route( '/commerce-user/reset/{email}/{timestamp}/{hash}', [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::resetPass', '_title' => 'Reset password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password_reset_form'] = new Route( '/commerce-user/reset/{email}', [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::getResetPassForm', '_title' => 'Reset password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); $routes['acm.external_user_password_reset_login'] = new Route( '/commerce-user/reset/{email}/{timestamp}/{hash}/login', [ '_controller' => 'Drupal\acm\Controller\CommerceUserController::resetPassLogin', '_title' => 'Reset password', ], [ '_commerce_user_is_logged_in' => 'FALSE', ], [ 'no_cache' => 'TRUE', ] ); return $routes; }
[ "public", "function", "routes", "(", ")", "{", "$", "routes", "=", "[", "]", ";", "// Only add the routes if we're using ecomm sessions, otherwise drupal user", "// accounts will be created for everyone and the core user login/logout", "// functionality can be used.", "if", "(", "!", "$", "this", "->", "config", "->", "get", "(", "'use_ecomm_sessions'", ")", ")", "{", "return", "$", "routes", ";", "}", "$", "external_registration_path", "=", "$", "this", "->", "config", "->", "get", "(", "'external_registration_path'", ")", "?", ":", "'/register'", ";", "$", "external_login_path", "=", "$", "this", "->", "config", "->", "get", "(", "'external_login_path'", ")", "?", ":", "'/login'", ";", "$", "external_logout_path", "=", "$", "this", "->", "config", "->", "get", "(", "'external_logout_path'", ")", "?", ":", "'/logout'", ";", "if", "(", "$", "this", "->", "config", "->", "get", "(", "'use_ecomm_pass_reset'", ")", ")", "{", "$", "ecomm_forgot_password_path", "=", "$", "this", "->", "config", "->", "get", "(", "'ecomm_forgot_password_path'", ")", "?", ":", "'/forgottenpassword'", ";", "$", "routes", "[", "'acm.ecomm_password_reset'", "]", "=", "new", "Route", "(", "$", "ecomm_forgot_password_path", ",", "[", "'_form'", "=>", "'Drupal\\acm\\Form\\CommerceUserPasswordTokenResetForm'", ",", "'_title'", "=>", "'Reset Password'", ",", "]", ",", "[", "// Authentication status will be checked within the form.", "'_access'", "=>", "'TRUE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "}", "$", "routes", "[", "'acm.external_user_registration'", "]", "=", "new", "Route", "(", "$", "external_registration_path", ",", "[", "'_form'", "=>", "'Drupal\\acm\\Form\\CommerceUserRegistrationForm'", ",", "'_title'", "=>", "'Create Account'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'FALSE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "$", "routes", "[", "'acm.external_user_login'", "]", "=", "new", "Route", "(", "$", "external_login_path", ",", "[", "'_form'", "=>", "'Drupal\\acm\\Form\\CommerceUserLoginForm'", ",", "'_title'", "=>", "'Log In'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'FALSE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "$", "routes", "[", "'acm.external_user_logout'", "]", "=", "new", "Route", "(", "$", "external_logout_path", ",", "[", "'_controller'", "=>", "'Drupal\\acm\\Controller\\CommerceUserController::logout'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'TRUE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "$", "routes", "[", "'acm.external_user_password'", "]", "=", "new", "Route", "(", "'/commerce-user/password'", ",", "[", "'_form'", "=>", "'Drupal\\acm\\Form\\CommerceUserPasswordForm'", ",", "'_title'", "=>", "'Reset your password'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'FALSE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "$", "routes", "[", "'acm.external_user_password_reset'", "]", "=", "new", "Route", "(", "'/commerce-user/reset/{email}/{timestamp}/{hash}'", ",", "[", "'_controller'", "=>", "'Drupal\\acm\\Controller\\CommerceUserController::resetPass'", ",", "'_title'", "=>", "'Reset password'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'FALSE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "$", "routes", "[", "'acm.external_user_password_reset_form'", "]", "=", "new", "Route", "(", "'/commerce-user/reset/{email}'", ",", "[", "'_controller'", "=>", "'Drupal\\acm\\Controller\\CommerceUserController::getResetPassForm'", ",", "'_title'", "=>", "'Reset password'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'FALSE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "$", "routes", "[", "'acm.external_user_password_reset_login'", "]", "=", "new", "Route", "(", "'/commerce-user/reset/{email}/{timestamp}/{hash}/login'", ",", "[", "'_controller'", "=>", "'Drupal\\acm\\Controller\\CommerceUserController::resetPassLogin'", ",", "'_title'", "=>", "'Reset password'", ",", "]", ",", "[", "'_commerce_user_is_logged_in'", "=>", "'FALSE'", ",", "]", ",", "[", "'no_cache'", "=>", "'TRUE'", ",", "]", ")", ";", "return", "$", "routes", ";", "}" ]
Returns an array of route objects. @return \Symfony\Component\Routing\Route[] An array of route objects.
[ "Returns", "an", "array", "of", "route", "objects", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Routing/CommerceUserRoutes.php#L36-L166
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractTickableInput.php
AbstractTickableInput.setInputLayout
public function setInputLayout($layout) { if ($layout === null) { $this->inputLayout = null; return $this; } if (!is_string($layout)) { throw new InvalidArgumentException(sprintf( 'Layout must be a string, received %s', (is_object($layout) ? get_class($layout) : gettype($layout)) )); } $supportedLayouts = $this->supportedInputLayouts(); if (!in_array($layout, $supportedLayouts)) { throw new OutOfBoundsException(sprintf( 'Unsupported layout [%s]; must be one of %s', $layout, implode(', ', $supportedLayouts) )); } $this->inputLayout = $layout; return $this; }
php
public function setInputLayout($layout) { if ($layout === null) { $this->inputLayout = null; return $this; } if (!is_string($layout)) { throw new InvalidArgumentException(sprintf( 'Layout must be a string, received %s', (is_object($layout) ? get_class($layout) : gettype($layout)) )); } $supportedLayouts = $this->supportedInputLayouts(); if (!in_array($layout, $supportedLayouts)) { throw new OutOfBoundsException(sprintf( 'Unsupported layout [%s]; must be one of %s', $layout, implode(', ', $supportedLayouts) )); } $this->inputLayout = $layout; return $this; }
[ "public", "function", "setInputLayout", "(", "$", "layout", ")", "{", "if", "(", "$", "layout", "===", "null", ")", "{", "$", "this", "->", "inputLayout", "=", "null", ";", "return", "$", "this", ";", "}", "if", "(", "!", "is_string", "(", "$", "layout", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Layout must be a string, received %s'", ",", "(", "is_object", "(", "$", "layout", ")", "?", "get_class", "(", "$", "layout", ")", ":", "gettype", "(", "$", "layout", ")", ")", ")", ")", ";", "}", "$", "supportedLayouts", "=", "$", "this", "->", "supportedInputLayouts", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "layout", ",", "$", "supportedLayouts", ")", ")", "{", "throw", "new", "OutOfBoundsException", "(", "sprintf", "(", "'Unsupported layout [%s]; must be one of %s'", ",", "$", "layout", ",", "implode", "(", "', '", ",", "$", "supportedLayouts", ")", ")", ")", ";", "}", "$", "this", "->", "inputLayout", "=", "$", "layout", ";", "return", "$", "this", ";", "}" ]
Set the property's input layout. @param string $layout The layout for the tickable elements. @throws InvalidArgumentException If the given layout is invalid. @throws OutOfBoundsException If the given layout is unsupported. @return AbstractTickableInput Chainable
[ "Set", "the", "property", "s", "input", "layout", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractTickableInput.php#L55-L82
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractTickableInput.php
AbstractTickableInput.inputLayouts
public function inputLayouts() { $supported = $this->supportedInputLayouts(); $layouts = []; foreach ($supported as $layout) { $layouts[$layout] = ($layout === $this->inputLayout()); } return $layouts; }
php
public function inputLayouts() { $supported = $this->supportedInputLayouts(); $layouts = []; foreach ($supported as $layout) { $layouts[$layout] = ($layout === $this->inputLayout()); } return $layouts; }
[ "public", "function", "inputLayouts", "(", ")", "{", "$", "supported", "=", "$", "this", "->", "supportedInputLayouts", "(", ")", ";", "$", "layouts", "=", "[", "]", ";", "foreach", "(", "$", "supported", "as", "$", "layout", ")", "{", "$", "layouts", "[", "$", "layout", "]", "=", "(", "$", "layout", "===", "$", "this", "->", "inputLayout", "(", ")", ")", ";", "}", "return", "$", "layouts", ";", "}" ]
Retrieve the input layouts; for templating. @return array
[ "Retrieve", "the", "input", "layouts", ";", "for", "templating", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractTickableInput.php#L103-L112
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.hasSecondaryMenu
public function hasSecondaryMenu() { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident])) { return $this->hasLinks() || $this->hasGroups() || $this->hasActions() || $this->showTitle() || $this->showDescription(); } return false; }
php
public function hasSecondaryMenu() { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident])) { return $this->hasLinks() || $this->hasGroups() || $this->hasActions() || $this->showTitle() || $this->showDescription(); } return false; }
[ "public", "function", "hasSecondaryMenu", "(", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", ")", ")", "{", "return", "$", "this", "->", "hasLinks", "(", ")", "||", "$", "this", "->", "hasGroups", "(", ")", "||", "$", "this", "->", "hasActions", "(", ")", "||", "$", "this", "->", "showTitle", "(", ")", "||", "$", "this", "->", "showDescription", "(", ")", ";", "}", "return", "false", ";", "}" ]
Determine if the secondary menu has anything. @return boolean
[ "Determine", "if", "the", "secondary", "menu", "has", "anything", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L185-L199
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.isTabbed
public function isTabbed() { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident])) { return $this->hasLinks() || $this->hasGroups() || $this->hasActions(); } return false; }
php
public function isTabbed() { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident])) { return $this->hasLinks() || $this->hasGroups() || $this->hasActions(); } return false; }
[ "public", "function", "isTabbed", "(", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", ")", ")", "{", "return", "$", "this", "->", "hasLinks", "(", ")", "||", "$", "this", "->", "hasGroups", "(", ")", "||", "$", "this", "->", "hasActions", "(", ")", ";", "}", "return", "false", ";", "}" ]
Determine if the secondary menu is accessible via a tab. @return boolean
[ "Determine", "if", "the", "secondary", "menu", "is", "accessible", "via", "a", "tab", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L206-L218
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.adminRoute
public function adminRoute() { if ($this->adminRoute === null) { $requestUri = (string)$this->httpRequest()->getUri(); $requestUri = str_replace($this->adminUrl(), '', $requestUri); $this->adminRoute = $requestUri; } return $this->adminRoute; }
php
public function adminRoute() { if ($this->adminRoute === null) { $requestUri = (string)$this->httpRequest()->getUri(); $requestUri = str_replace($this->adminUrl(), '', $requestUri); $this->adminRoute = $requestUri; } return $this->adminRoute; }
[ "public", "function", "adminRoute", "(", ")", "{", "if", "(", "$", "this", "->", "adminRoute", "===", "null", ")", "{", "$", "requestUri", "=", "(", "string", ")", "$", "this", "->", "httpRequest", "(", ")", "->", "getUri", "(", ")", ";", "$", "requestUri", "=", "str_replace", "(", "$", "this", "->", "adminUrl", "(", ")", ",", "''", ",", "$", "requestUri", ")", ";", "$", "this", "->", "adminRoute", "=", "$", "requestUri", ";", "}", "return", "$", "this", "->", "adminRoute", ";", "}" ]
Retrieve the current route path. @return string|null
[ "Retrieve", "the", "current", "route", "path", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L235-L245
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.isCurrentItem
public function isCurrentItem($linkIdent) { $context = array_filter([ $this->currentItem(), $this->objType(), $this->adminRoute(), ]); $matches = array_intersect((array)$linkIdent, $context); return !!$matches; }
php
public function isCurrentItem($linkIdent) { $context = array_filter([ $this->currentItem(), $this->objType(), $this->adminRoute(), ]); $matches = array_intersect((array)$linkIdent, $context); return !!$matches; }
[ "public", "function", "isCurrentItem", "(", "$", "linkIdent", ")", "{", "$", "context", "=", "array_filter", "(", "[", "$", "this", "->", "currentItem", "(", ")", ",", "$", "this", "->", "objType", "(", ")", ",", "$", "this", "->", "adminRoute", "(", ")", ",", "]", ")", ";", "$", "matches", "=", "array_intersect", "(", "(", "array", ")", "$", "linkIdent", ",", "$", "context", ")", ";", "return", "!", "!", "$", "matches", ";", "}" ]
Computes the intersection of values to determine if the link is the current item. @param mixed $linkIdent The link's value(s) to check. @return boolean
[ "Computes", "the", "intersection", "of", "values", "to", "determine", "if", "the", "link", "is", "the", "current", "item", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L271-L282
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.title
public function title() { if ($this->title === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); $this->title = ''; if (isset($metadata[$ident]['title'])) { $this->setTitle($metadata[$ident]['title']); } } return $this->title; }
php
public function title() { if ($this->title === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); $this->title = ''; if (isset($metadata[$ident]['title'])) { $this->setTitle($metadata[$ident]['title']); } } return $this->title; }
[ "public", "function", "title", "(", ")", "{", "if", "(", "$", "this", "->", "title", "===", "null", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "$", "this", "->", "title", "=", "''", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'title'", "]", ")", ")", "{", "$", "this", "->", "setTitle", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'title'", "]", ")", ";", "}", "}", "return", "$", "this", "->", "title", ";", "}" ]
Retrieve the title of the secondary menu. @return \Charcoal\Translator\Translation|string|null
[ "Retrieve", "the", "title", "of", "the", "secondary", "menu", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L339-L353
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.displayType
public function displayType() { if ($this->displayType === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident]['display_type'])) { $this->setDisplayType($metadata[$ident]['display_type']); } else { $this->displayType = ''; } } return $this->displayType; }
php
public function displayType() { if ($this->displayType === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident]['display_type'])) { $this->setDisplayType($metadata[$ident]['display_type']); } else { $this->displayType = ''; } } return $this->displayType; }
[ "public", "function", "displayType", "(", ")", "{", "if", "(", "$", "this", "->", "displayType", "===", "null", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'display_type'", "]", ")", ")", "{", "$", "this", "->", "setDisplayType", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'display_type'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "displayType", "=", "''", ";", "}", "}", "return", "$", "this", "->", "displayType", ";", "}" ]
Retrieve the display type of the secondary menu's contents. @return string|null
[ "Retrieve", "the", "display", "type", "of", "the", "secondary", "menu", "s", "contents", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L506-L520
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.displayOptions
public function displayOptions() { if ($this->displayOptions === null) { $this->setDisplayOptions($this->defaultDisplayOptions()); $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident]['display_options'])) { $options = $metadata[$ident]['display_options']; if (!is_array($options)) { throw new RuntimeException('The display options must be an associative array.'); } $this->setDisplayOptions(array_merge($this->displayOptions, $options)); } } return $this->displayOptions; }
php
public function displayOptions() { if ($this->displayOptions === null) { $this->setDisplayOptions($this->defaultDisplayOptions()); $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident]['display_options'])) { $options = $metadata[$ident]['display_options']; if (!is_array($options)) { throw new RuntimeException('The display options must be an associative array.'); } $this->setDisplayOptions(array_merge($this->displayOptions, $options)); } } return $this->displayOptions; }
[ "public", "function", "displayOptions", "(", ")", "{", "if", "(", "$", "this", "->", "displayOptions", "===", "null", ")", "{", "$", "this", "->", "setDisplayOptions", "(", "$", "this", "->", "defaultDisplayOptions", "(", ")", ")", ";", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'display_options'", "]", ")", ")", "{", "$", "options", "=", "$", "metadata", "[", "$", "ident", "]", "[", "'display_options'", "]", ";", "if", "(", "!", "is_array", "(", "$", "options", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The display options must be an associative array.'", ")", ";", "}", "$", "this", "->", "setDisplayOptions", "(", "array_merge", "(", "$", "this", "->", "displayOptions", ",", "$", "options", ")", ")", ";", "}", "}", "return", "$", "this", "->", "displayOptions", ";", "}" ]
Retrieve the display options for the secondary menu. @throws RuntimeException If the display options are not an associative array. @return array
[ "Retrieve", "the", "display", "options", "for", "the", "secondary", "menu", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L562-L582
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.setGroups
public function setGroups(array $groups) { $this->groups = []; foreach ($groups as $groupIdent => $group) { $this->addGroup($groupIdent, $group); } uasort($this->groups, [ $this, 'sortGroupsByPriority' ]); // Remove items that are not active. $this->groups = array_filter($this->groups, function($item) { return ($item->active()); }); return $this; }
php
public function setGroups(array $groups) { $this->groups = []; foreach ($groups as $groupIdent => $group) { $this->addGroup($groupIdent, $group); } uasort($this->groups, [ $this, 'sortGroupsByPriority' ]); // Remove items that are not active. $this->groups = array_filter($this->groups, function($item) { return ($item->active()); }); return $this; }
[ "public", "function", "setGroups", "(", "array", "$", "groups", ")", "{", "$", "this", "->", "groups", "=", "[", "]", ";", "foreach", "(", "$", "groups", "as", "$", "groupIdent", "=>", "$", "group", ")", "{", "$", "this", "->", "addGroup", "(", "$", "groupIdent", ",", "$", "group", ")", ";", "}", "uasort", "(", "$", "this", "->", "groups", ",", "[", "$", "this", ",", "'sortGroupsByPriority'", "]", ")", ";", "// Remove items that are not active.", "$", "this", "->", "groups", "=", "array_filter", "(", "$", "this", "->", "groups", ",", "function", "(", "$", "item", ")", "{", "return", "(", "$", "item", "->", "active", "(", ")", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Set the secondary menu's groups. @param array $groups A collection of group structures. @return self
[ "Set", "the", "secondary", "menu", "s", "groups", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L627-L643
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.addGroup
public function addGroup($groupIdent, $group) { if (!is_string($groupIdent)) { throw new InvalidArgumentException( 'Group identifier must be a string' ); } if ($group instanceof SecondaryMenuGroupInterface) { $group->setSecondaryMenu($this); $group->setIdent($groupIdent); $this->groups[] = $group; } elseif (is_array($group)) { if (isset($group['ident'])) { $groupIdent = $group['ident']; } else { $group['ident'] = $groupIdent; } $displayOptions = $this->displayOptions(); if (isset($group['display_options'])) { $displayOptions = array_merge($displayOptions, $group['display_options']); } $group['collapsed'] = $displayOptions['collapsed']; $group['parented'] = $displayOptions['parented']; if (!isset($group['display_type'])) { $group['display_type'] = $this->displayType(); } $collapsible = ($group['display_type'] === 'collapsible'); if ($collapsible) { $group['group_id'] = uniqid('collapsible_'); } $g = $this->secondaryMenu()->create($this->defaultGroupType()); $g->setSecondaryMenu($this); $g->setData($group); $group = $g; } elseif ($group === false || $group === null) { return $this; } else { throw new InvalidArgumentException(sprintf( 'Group must be an instance of %s or an array of form group options, received %s', 'SecondaryMenuGroupInterface', (is_object($group) ? get_class($group) : gettype($group)) )); } if ($g->isAuthorized() === false) { return $this; } $this->groups[] = $g; return $this; }
php
public function addGroup($groupIdent, $group) { if (!is_string($groupIdent)) { throw new InvalidArgumentException( 'Group identifier must be a string' ); } if ($group instanceof SecondaryMenuGroupInterface) { $group->setSecondaryMenu($this); $group->setIdent($groupIdent); $this->groups[] = $group; } elseif (is_array($group)) { if (isset($group['ident'])) { $groupIdent = $group['ident']; } else { $group['ident'] = $groupIdent; } $displayOptions = $this->displayOptions(); if (isset($group['display_options'])) { $displayOptions = array_merge($displayOptions, $group['display_options']); } $group['collapsed'] = $displayOptions['collapsed']; $group['parented'] = $displayOptions['parented']; if (!isset($group['display_type'])) { $group['display_type'] = $this->displayType(); } $collapsible = ($group['display_type'] === 'collapsible'); if ($collapsible) { $group['group_id'] = uniqid('collapsible_'); } $g = $this->secondaryMenu()->create($this->defaultGroupType()); $g->setSecondaryMenu($this); $g->setData($group); $group = $g; } elseif ($group === false || $group === null) { return $this; } else { throw new InvalidArgumentException(sprintf( 'Group must be an instance of %s or an array of form group options, received %s', 'SecondaryMenuGroupInterface', (is_object($group) ? get_class($group) : gettype($group)) )); } if ($g->isAuthorized() === false) { return $this; } $this->groups[] = $g; return $this; }
[ "public", "function", "addGroup", "(", "$", "groupIdent", ",", "$", "group", ")", "{", "if", "(", "!", "is_string", "(", "$", "groupIdent", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Group identifier must be a string'", ")", ";", "}", "if", "(", "$", "group", "instanceof", "SecondaryMenuGroupInterface", ")", "{", "$", "group", "->", "setSecondaryMenu", "(", "$", "this", ")", ";", "$", "group", "->", "setIdent", "(", "$", "groupIdent", ")", ";", "$", "this", "->", "groups", "[", "]", "=", "$", "group", ";", "}", "elseif", "(", "is_array", "(", "$", "group", ")", ")", "{", "if", "(", "isset", "(", "$", "group", "[", "'ident'", "]", ")", ")", "{", "$", "groupIdent", "=", "$", "group", "[", "'ident'", "]", ";", "}", "else", "{", "$", "group", "[", "'ident'", "]", "=", "$", "groupIdent", ";", "}", "$", "displayOptions", "=", "$", "this", "->", "displayOptions", "(", ")", ";", "if", "(", "isset", "(", "$", "group", "[", "'display_options'", "]", ")", ")", "{", "$", "displayOptions", "=", "array_merge", "(", "$", "displayOptions", ",", "$", "group", "[", "'display_options'", "]", ")", ";", "}", "$", "group", "[", "'collapsed'", "]", "=", "$", "displayOptions", "[", "'collapsed'", "]", ";", "$", "group", "[", "'parented'", "]", "=", "$", "displayOptions", "[", "'parented'", "]", ";", "if", "(", "!", "isset", "(", "$", "group", "[", "'display_type'", "]", ")", ")", "{", "$", "group", "[", "'display_type'", "]", "=", "$", "this", "->", "displayType", "(", ")", ";", "}", "$", "collapsible", "=", "(", "$", "group", "[", "'display_type'", "]", "===", "'collapsible'", ")", ";", "if", "(", "$", "collapsible", ")", "{", "$", "group", "[", "'group_id'", "]", "=", "uniqid", "(", "'collapsible_'", ")", ";", "}", "$", "g", "=", "$", "this", "->", "secondaryMenu", "(", ")", "->", "create", "(", "$", "this", "->", "defaultGroupType", "(", ")", ")", ";", "$", "g", "->", "setSecondaryMenu", "(", "$", "this", ")", ";", "$", "g", "->", "setData", "(", "$", "group", ")", ";", "$", "group", "=", "$", "g", ";", "}", "elseif", "(", "$", "group", "===", "false", "||", "$", "group", "===", "null", ")", "{", "return", "$", "this", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Group must be an instance of %s or an array of form group options, received %s'", ",", "'SecondaryMenuGroupInterface'", ",", "(", "is_object", "(", "$", "group", ")", "?", "get_class", "(", "$", "group", ")", ":", "gettype", "(", "$", "group", ")", ")", ")", ")", ";", "}", "if", "(", "$", "g", "->", "isAuthorized", "(", ")", "===", "false", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "groups", "[", "]", "=", "$", "g", ";", "return", "$", "this", ";", "}" ]
Add a secondary menu group. @param string $groupIdent The group identifier. @param array|SecondaryMenuGroupInterface $group The group object or structure. @throws InvalidArgumentException If the identifier is not a string or the group is invalid. @return self
[ "Add", "a", "secondary", "menu", "group", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L653-L713
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.groups
public function groups() { if ($this->groups === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); $this->groups = []; if (isset($metadata[$ident]['groups'])) { $groups = $metadata[$ident]['groups']; if (is_array($groups)) { $this->setGroups($groups); } } } return $this->groups; }
php
public function groups() { if ($this->groups === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); $this->groups = []; if (isset($metadata[$ident]['groups'])) { $groups = $metadata[$ident]['groups']; if (is_array($groups)) { $this->setGroups($groups); } } } return $this->groups; }
[ "public", "function", "groups", "(", ")", "{", "if", "(", "$", "this", "->", "groups", "===", "null", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "$", "this", "->", "groups", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'groups'", "]", ")", ")", "{", "$", "groups", "=", "$", "metadata", "[", "$", "ident", "]", "[", "'groups'", "]", ";", "if", "(", "is_array", "(", "$", "groups", ")", ")", "{", "$", "this", "->", "setGroups", "(", "$", "groups", ")", ";", "}", "}", "}", "return", "$", "this", "->", "groups", ";", "}" ]
Retrieve the secondary menu groups. @return array
[ "Retrieve", "the", "secondary", "menu", "groups", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L720-L737
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.numLinks
public function numLinks() { if (!is_array($this->links()) && !($this->links() instanceof \Traversable)) { return 0; } $links = array_filter($this->links, function ($link) { if (isset($link['active']) && !$link['active']) { return false; } if (isset($link['required_acl_permissions'])) { $link['permissions'] = $link['required_acl_permissions']; unset($link['required_acl_permissions']); } if (isset($link['permissions'])) { if ($this->hasPermissions($link['permissions']) === false) { return false; } } return true; }); return count($links); }
php
public function numLinks() { if (!is_array($this->links()) && !($this->links() instanceof \Traversable)) { return 0; } $links = array_filter($this->links, function ($link) { if (isset($link['active']) && !$link['active']) { return false; } if (isset($link['required_acl_permissions'])) { $link['permissions'] = $link['required_acl_permissions']; unset($link['required_acl_permissions']); } if (isset($link['permissions'])) { if ($this->hasPermissions($link['permissions']) === false) { return false; } } return true; }); return count($links); }
[ "public", "function", "numLinks", "(", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "links", "(", ")", ")", "&&", "!", "(", "$", "this", "->", "links", "(", ")", "instanceof", "\\", "Traversable", ")", ")", "{", "return", "0", ";", "}", "$", "links", "=", "array_filter", "(", "$", "this", "->", "links", ",", "function", "(", "$", "link", ")", "{", "if", "(", "isset", "(", "$", "link", "[", "'active'", "]", ")", "&&", "!", "$", "link", "[", "'active'", "]", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "link", "[", "'required_acl_permissions'", "]", ")", ")", "{", "$", "link", "[", "'permissions'", "]", "=", "$", "link", "[", "'required_acl_permissions'", "]", ";", "unset", "(", "$", "link", "[", "'required_acl_permissions'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "link", "[", "'permissions'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "hasPermissions", "(", "$", "link", "[", "'permissions'", "]", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", ")", ";", "return", "count", "(", "$", "links", ")", ";", "}" ]
Count the number of secondary menu links. @return integer
[ "Count", "the", "number", "of", "secondary", "menu", "links", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L764-L790
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.secondaryMenuActions
public function secondaryMenuActions() { if ($this->secondaryMenuActions === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident]['actions'])) { $actions = $metadata[$ident]['actions']; } else { $actions = []; } $this->setSecondaryMenuActions($actions); } if ($this->parsedSecondaryMenuActions === false) { $this->parsedSecondaryMenuActions = true; $this->secondaryMenuActions = $this->createSecondaryMenuActions($this->secondaryMenuActions); } return $this->secondaryMenuActions; }
php
public function secondaryMenuActions() { if ($this->secondaryMenuActions === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); if (isset($metadata[$ident]['actions'])) { $actions = $metadata[$ident]['actions']; } else { $actions = []; } $this->setSecondaryMenuActions($actions); } if ($this->parsedSecondaryMenuActions === false) { $this->parsedSecondaryMenuActions = true; $this->secondaryMenuActions = $this->createSecondaryMenuActions($this->secondaryMenuActions); } return $this->secondaryMenuActions; }
[ "public", "function", "secondaryMenuActions", "(", ")", "{", "if", "(", "$", "this", "->", "secondaryMenuActions", "===", "null", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'actions'", "]", ")", ")", "{", "$", "actions", "=", "$", "metadata", "[", "$", "ident", "]", "[", "'actions'", "]", ";", "}", "else", "{", "$", "actions", "=", "[", "]", ";", "}", "$", "this", "->", "setSecondaryMenuActions", "(", "$", "actions", ")", ";", "}", "if", "(", "$", "this", "->", "parsedSecondaryMenuActions", "===", "false", ")", "{", "$", "this", "->", "parsedSecondaryMenuActions", "=", "true", ";", "$", "this", "->", "secondaryMenuActions", "=", "$", "this", "->", "createSecondaryMenuActions", "(", "$", "this", "->", "secondaryMenuActions", ")", ";", "}", "return", "$", "this", "->", "secondaryMenuActions", ";", "}" ]
Retrieve the secondary menu's actions. @return array
[ "Retrieve", "the", "secondary", "menu", "s", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L839-L858
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.description
public function description() { if ($this->description === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); $this->description = ''; if (isset($metadata[$ident]['description'])) { $this->setDescription($metadata[$ident]['description']); } } return $this->description; }
php
public function description() { if ($this->description === null) { $ident = $this->ident(); $metadata = $this->adminSecondaryMenu(); $this->description = ''; if (isset($metadata[$ident]['description'])) { $this->setDescription($metadata[$ident]['description']); } } return $this->description; }
[ "public", "function", "description", "(", ")", "{", "if", "(", "$", "this", "->", "description", "===", "null", ")", "{", "$", "ident", "=", "$", "this", "->", "ident", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "adminSecondaryMenu", "(", ")", ";", "$", "this", "->", "description", "=", "''", ";", "if", "(", "isset", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'description'", "]", ")", ")", "{", "$", "this", "->", "setDescription", "(", "$", "metadata", "[", "$", "ident", "]", "[", "'description'", "]", ")", ";", "}", "}", "return", "$", "this", "->", "description", ";", "}" ]
Retrieve the description of the secondary menu. @return \Charcoal\Translator\Translation|string|null
[ "Retrieve", "the", "description", "of", "the", "secondary", "menu", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L878-L892
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.secondaryMenu
protected function secondaryMenu() { if (!isset($this->secondaryMenu)) { throw new RuntimeException(sprintf( 'Secondary Menu Group Factory is not defined for "%s"', get_class($this) )); } return $this->secondaryMenu; }
php
protected function secondaryMenu() { if (!isset($this->secondaryMenu)) { throw new RuntimeException(sprintf( 'Secondary Menu Group Factory is not defined for "%s"', get_class($this) )); } return $this->secondaryMenu; }
[ "protected", "function", "secondaryMenu", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "secondaryMenu", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Secondary Menu Group Factory is not defined for \"%s\"'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "return", "$", "this", "->", "secondaryMenu", ";", "}" ]
Retrieve the secondary menu group factory. @throws RuntimeException If the secondary menu group factory was not previously set. @return FactoryInterface
[ "Retrieve", "the", "secondary", "menu", "group", "factory", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L973-L983
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/SecondaryMenuWidget.php
SecondaryMenuWidget.setSecondaryMenuActions
protected function setSecondaryMenuActions(array $actions) { $this->parsedSecondaryMenuActions = false; $this->secondaryMenuActions = $this->mergeActions($this->defaultSecondaryMenuActions(), $actions); return $this; }
php
protected function setSecondaryMenuActions(array $actions) { $this->parsedSecondaryMenuActions = false; $this->secondaryMenuActions = $this->mergeActions($this->defaultSecondaryMenuActions(), $actions); return $this; }
[ "protected", "function", "setSecondaryMenuActions", "(", "array", "$", "actions", ")", "{", "$", "this", "->", "parsedSecondaryMenuActions", "=", "false", ";", "$", "this", "->", "secondaryMenuActions", "=", "$", "this", "->", "mergeActions", "(", "$", "this", "->", "defaultSecondaryMenuActions", "(", ")", ",", "$", "actions", ")", ";", "return", "$", "this", ";", "}" ]
Set the secondary menu's actions. @param array $actions One or more actions. @return self
[ "Set", "the", "secondary", "menu", "s", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/SecondaryMenuWidget.php#L991-L998
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/Graph/AbstractTimeGraphWidget.php
AbstractTimeGraphWidget.fillRows
protected function fillRows(array $rows) { $row = []; $seriesOptions = $this->seriesOptions(); foreach ($seriesOptions as $serieId => $serieOpts) { $row[$serieId] = '0'; } $starts = clone($this->startDate()); $ends = $this->endDate(); while ($starts < $ends) { $x = $starts->format($this->dateFormat()); if (!isset($rows[$x])) { $rows[$x] = $row; } $starts->add($this->dateInterval()); } ksort($rows); return $rows; }
php
protected function fillRows(array $rows) { $row = []; $seriesOptions = $this->seriesOptions(); foreach ($seriesOptions as $serieId => $serieOpts) { $row[$serieId] = '0'; } $starts = clone($this->startDate()); $ends = $this->endDate(); while ($starts < $ends) { $x = $starts->format($this->dateFormat()); if (!isset($rows[$x])) { $rows[$x] = $row; } $starts->add($this->dateInterval()); } ksort($rows); return $rows; }
[ "protected", "function", "fillRows", "(", "array", "$", "rows", ")", "{", "$", "row", "=", "[", "]", ";", "$", "seriesOptions", "=", "$", "this", "->", "seriesOptions", "(", ")", ";", "foreach", "(", "$", "seriesOptions", "as", "$", "serieId", "=>", "$", "serieOpts", ")", "{", "$", "row", "[", "$", "serieId", "]", "=", "'0'", ";", "}", "$", "starts", "=", "clone", "(", "$", "this", "->", "startDate", "(", ")", ")", ";", "$", "ends", "=", "$", "this", "->", "endDate", "(", ")", ";", "while", "(", "$", "starts", "<", "$", "ends", ")", "{", "$", "x", "=", "$", "starts", "->", "format", "(", "$", "this", "->", "dateFormat", "(", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "rows", "[", "$", "x", "]", ")", ")", "{", "$", "rows", "[", "$", "x", "]", "=", "$", "row", ";", "}", "$", "starts", "->", "add", "(", "$", "this", "->", "dateInterval", "(", ")", ")", ";", "}", "ksort", "(", "$", "rows", ")", ";", "return", "$", "rows", ";", "}" ]
Fill all rows with 0 value for all series, when it is unset. @param array $rows The row structure to fill. @return array
[ "Fill", "all", "rows", "with", "0", "value", "for", "all", "series", "when", "it", "is", "unset", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/Graph/AbstractTimeGraphWidget.php#L324-L343
train
acquia/commerce-manager
modules/acm/src/DatabaseSessionStoreFactory.php
DatabaseSessionStoreFactory.get
public function get($collection) { // Store the data for this collection in the database. $storage = $this->storageFactory->get("acm.database_store.$collection"); return new DatabaseSessionStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire); }
php
public function get($collection) { // Store the data for this collection in the database. $storage = $this->storageFactory->get("acm.database_store.$collection"); return new DatabaseSessionStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire); }
[ "public", "function", "get", "(", "$", "collection", ")", "{", "// Store the data for this collection in the database.", "$", "storage", "=", "$", "this", "->", "storageFactory", "->", "get", "(", "\"acm.database_store.$collection\"", ")", ";", "return", "new", "DatabaseSessionStore", "(", "$", "storage", ",", "$", "this", "->", "lockBackend", ",", "$", "this", "->", "currentUser", ",", "$", "this", "->", "requestStack", ",", "$", "this", "->", "expire", ")", ";", "}" ]
Creates a DatabaseSessionStore. @param string $collection The collection name to use for this key/value store. This is typically a shared namespace or module name, e.g. 'views', 'entity', etc. @return \Drupal\acm\DatabaseSessionStore An instance of the key/value store.
[ "Creates", "a", "DatabaseSessionStore", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/DatabaseSessionStoreFactory.php#L47-L51
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/ColorPickerInput.php
ColorPickerInput.pickerOptions
public function pickerOptions() { if ($this->pickerOptions === null) { $this->pickerOptions = $this->defaultPickerOptions(); } return $this->pickerOptions; }
php
public function pickerOptions() { if ($this->pickerOptions === null) { $this->pickerOptions = $this->defaultPickerOptions(); } return $this->pickerOptions; }
[ "public", "function", "pickerOptions", "(", ")", "{", "if", "(", "$", "this", "->", "pickerOptions", "===", "null", ")", "{", "$", "this", "->", "pickerOptions", "=", "$", "this", "->", "defaultPickerOptions", "(", ")", ";", "}", "return", "$", "this", "->", "pickerOptions", ";", "}" ]
Retrieve the color picker's options. @return array
[ "Retrieve", "the", "color", "picker", "s", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/ColorPickerInput.php#L90-L97
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/DateTimePickerInput.php
DateTimePickerInput.defaultPickerOptions
public function defaultPickerOptions() { $date = null; if ($this->inputVal() !== '') { $date = new \DateTime($this->inputVal()); } return [ 'format' => self::DEFAULT_JS_FORMAT, 'defaultDate' => $date ? $date->format(\DateTime::ISO8601) : null ]; }
php
public function defaultPickerOptions() { $date = null; if ($this->inputVal() !== '') { $date = new \DateTime($this->inputVal()); } return [ 'format' => self::DEFAULT_JS_FORMAT, 'defaultDate' => $date ? $date->format(\DateTime::ISO8601) : null ]; }
[ "public", "function", "defaultPickerOptions", "(", ")", "{", "$", "date", "=", "null", ";", "if", "(", "$", "this", "->", "inputVal", "(", ")", "!==", "''", ")", "{", "$", "date", "=", "new", "\\", "DateTime", "(", "$", "this", "->", "inputVal", "(", ")", ")", ";", "}", "return", "[", "'format'", "=>", "self", "::", "DEFAULT_JS_FORMAT", ",", "'defaultDate'", "=>", "$", "date", "?", "$", "date", "->", "format", "(", "\\", "DateTime", "::", "ISO8601", ")", ":", "null", "]", ";", "}" ]
Retrieve the default color picker options. @return array
[ "Retrieve", "the", "default", "color", "picker", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/DateTimePickerInput.php#L133-L145
train
acquia/commerce-manager
modules/acm/src/VerifyMapping.php
VerifyMapping.debugLogger
protected function debugLogger(string $message, array $context = []) { if ($this->debug) { $this->logger->debug($message, $context); } }
php
protected function debugLogger(string $message, array $context = []) { if ($this->debug) { $this->logger->debug($message, $context); } }
[ "protected", "function", "debugLogger", "(", "string", "$", "message", ",", "array", "$", "context", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "$", "message", ",", "$", "context", ")", ";", "}", "}" ]
Write to the log only if the debug flag is set true. @param string $message The message to write to the log. @param array $context Optional array to write to the log, nominally to convey the context.
[ "Write", "to", "the", "log", "only", "if", "the", "debug", "flag", "is", "set", "true", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/VerifyMapping.php#L85-L89
train
acquia/commerce-manager
modules/acm_payment/src/Plugin/PaymentMethod/Braintree.php
Braintree.getToken
public function getToken() { $cid = 'acm_payment:braintree_token'; $token = NULL; if ($cache = \Drupal::cache()->get($cid)) { $token = $cache->data; } else { $token = \Drupal::service('acm.api')->getPaymentToken('braintree'); \Drupal::cache()->set($cid, $token); } return $token; }
php
public function getToken() { $cid = 'acm_payment:braintree_token'; $token = NULL; if ($cache = \Drupal::cache()->get($cid)) { $token = $cache->data; } else { $token = \Drupal::service('acm.api')->getPaymentToken('braintree'); \Drupal::cache()->set($cid, $token); } return $token; }
[ "public", "function", "getToken", "(", ")", "{", "$", "cid", "=", "'acm_payment:braintree_token'", ";", "$", "token", "=", "NULL", ";", "if", "(", "$", "cache", "=", "\\", "Drupal", "::", "cache", "(", ")", "->", "get", "(", "$", "cid", ")", ")", "{", "$", "token", "=", "$", "cache", "->", "data", ";", "}", "else", "{", "$", "token", "=", "\\", "Drupal", "::", "service", "(", "'acm.api'", ")", "->", "getPaymentToken", "(", "'braintree'", ")", ";", "\\", "Drupal", "::", "cache", "(", ")", "->", "set", "(", "$", "cid", ",", "$", "token", ")", ";", "}", "return", "$", "token", ";", "}" ]
Get and cache the token used for a transaction.
[ "Get", "and", "cache", "the", "token", "used", "for", "a", "transaction", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_payment/src/Plugin/PaymentMethod/Braintree.php#L92-L105
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/CheckoutFlow/CheckoutFlowBase.php
CheckoutFlowBase.processStepId
protected function processStepId($requested_step_id) { $cart = $this->cartStorage; // Redirect back to cart page if cart is empty. if ($cart->isEmpty()) { throw new NeedsRedirectException(Url::fromRoute('acm_cart.cart')->toString()); } $cart_step_id = $cart->getCheckoutStep(); $step_ids = array_keys($this->getVisibleSteps()); $step_id = $requested_step_id; if (empty($step_id) || !in_array($step_id, $step_ids)) { // Take the step ID from the cart, or default to the first one. $step_id = $cart_step_id; if (empty($step_id)) { $step_id = reset($step_ids); } } $config = $this->getConfiguration(); $validate_current_step = $config['validate_current_step']; if (empty($validate_current_step)) { return $step_id; } // If user is on a certain step in their cart, check that the step being // processed is not further along in the checkout process then their last // completed step. If they haven't started the checkout yet, make sure they // can't get past the first step. $step_index = array_search($step_id, $step_ids); if (empty($cart_step_id)) { $first_step = reset($step_ids); if ($step_index > $first_step) { return $this->redirectToStep($first_step); } } else { $cart_step_index = array_search($cart_step_id, $step_ids); // Step being processed is further along than they should be, redirect // back to step they still need to complete. if ($step_index > $cart_step_index) { return $this->redirectToStep($cart_step_id); } } return $step_id; }
php
protected function processStepId($requested_step_id) { $cart = $this->cartStorage; // Redirect back to cart page if cart is empty. if ($cart->isEmpty()) { throw new NeedsRedirectException(Url::fromRoute('acm_cart.cart')->toString()); } $cart_step_id = $cart->getCheckoutStep(); $step_ids = array_keys($this->getVisibleSteps()); $step_id = $requested_step_id; if (empty($step_id) || !in_array($step_id, $step_ids)) { // Take the step ID from the cart, or default to the first one. $step_id = $cart_step_id; if (empty($step_id)) { $step_id = reset($step_ids); } } $config = $this->getConfiguration(); $validate_current_step = $config['validate_current_step']; if (empty($validate_current_step)) { return $step_id; } // If user is on a certain step in their cart, check that the step being // processed is not further along in the checkout process then their last // completed step. If they haven't started the checkout yet, make sure they // can't get past the first step. $step_index = array_search($step_id, $step_ids); if (empty($cart_step_id)) { $first_step = reset($step_ids); if ($step_index > $first_step) { return $this->redirectToStep($first_step); } } else { $cart_step_index = array_search($cart_step_id, $step_ids); // Step being processed is further along than they should be, redirect // back to step they still need to complete. if ($step_index > $cart_step_index) { return $this->redirectToStep($cart_step_id); } } return $step_id; }
[ "protected", "function", "processStepId", "(", "$", "requested_step_id", ")", "{", "$", "cart", "=", "$", "this", "->", "cartStorage", ";", "// Redirect back to cart page if cart is empty.", "if", "(", "$", "cart", "->", "isEmpty", "(", ")", ")", "{", "throw", "new", "NeedsRedirectException", "(", "Url", "::", "fromRoute", "(", "'acm_cart.cart'", ")", "->", "toString", "(", ")", ")", ";", "}", "$", "cart_step_id", "=", "$", "cart", "->", "getCheckoutStep", "(", ")", ";", "$", "step_ids", "=", "array_keys", "(", "$", "this", "->", "getVisibleSteps", "(", ")", ")", ";", "$", "step_id", "=", "$", "requested_step_id", ";", "if", "(", "empty", "(", "$", "step_id", ")", "||", "!", "in_array", "(", "$", "step_id", ",", "$", "step_ids", ")", ")", "{", "// Take the step ID from the cart, or default to the first one.", "$", "step_id", "=", "$", "cart_step_id", ";", "if", "(", "empty", "(", "$", "step_id", ")", ")", "{", "$", "step_id", "=", "reset", "(", "$", "step_ids", ")", ";", "}", "}", "$", "config", "=", "$", "this", "->", "getConfiguration", "(", ")", ";", "$", "validate_current_step", "=", "$", "config", "[", "'validate_current_step'", "]", ";", "if", "(", "empty", "(", "$", "validate_current_step", ")", ")", "{", "return", "$", "step_id", ";", "}", "// If user is on a certain step in their cart, check that the step being", "// processed is not further along in the checkout process then their last", "// completed step. If they haven't started the checkout yet, make sure they", "// can't get past the first step.", "$", "step_index", "=", "array_search", "(", "$", "step_id", ",", "$", "step_ids", ")", ";", "if", "(", "empty", "(", "$", "cart_step_id", ")", ")", "{", "$", "first_step", "=", "reset", "(", "$", "step_ids", ")", ";", "if", "(", "$", "step_index", ">", "$", "first_step", ")", "{", "return", "$", "this", "->", "redirectToStep", "(", "$", "first_step", ")", ";", "}", "}", "else", "{", "$", "cart_step_index", "=", "array_search", "(", "$", "cart_step_id", ",", "$", "step_ids", ")", ";", "// Step being processed is further along than they should be, redirect", "// back to step they still need to complete.", "if", "(", "$", "step_index", ">", "$", "cart_step_index", ")", "{", "return", "$", "this", "->", "redirectToStep", "(", "$", "cart_step_id", ")", ";", "}", "}", "return", "$", "step_id", ";", "}" ]
Processes the requested step ID. @param string $requested_step_id The step ID. @return string The processed step ID. @throws NeedsRedirectException Throws exception when cart is empty.
[ "Processes", "the", "requested", "step", "ID", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutFlow/CheckoutFlowBase.php#L121-L167
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/CheckoutFlow/CheckoutFlowBase.php
CheckoutFlowBase.actions
protected function actions(array $form, FormStateInterface $form_state) { $steps = $this->getVisibleSteps(); $next_step_id = $this->getNextStepId(); $previous_step_id = $this->getPreviousStepId(); $has_next_step = $next_step_id && isset($steps[$next_step_id]['next_label']); $has_previous_step = $previous_step_id && isset($steps[$previous_step_id]['previous_label']); $actions = [ '#type' => 'actions', '#access' => $has_next_step, ]; if ($has_next_step) { $actions['next'] = [ '#type' => 'submit', '#value' => $steps[$next_step_id]['next_label'], '#button_type' => 'primary', '#submit' => ['::submitForm'], ]; if ($has_previous_step) { $label = $steps[$previous_step_id]['previous_label']; $actions['next']['#suffix'] = Link::createFromRoute($label, 'acm_checkout.form', [ 'step' => $previous_step_id, ])->toString(); } } return $actions; }
php
protected function actions(array $form, FormStateInterface $form_state) { $steps = $this->getVisibleSteps(); $next_step_id = $this->getNextStepId(); $previous_step_id = $this->getPreviousStepId(); $has_next_step = $next_step_id && isset($steps[$next_step_id]['next_label']); $has_previous_step = $previous_step_id && isset($steps[$previous_step_id]['previous_label']); $actions = [ '#type' => 'actions', '#access' => $has_next_step, ]; if ($has_next_step) { $actions['next'] = [ '#type' => 'submit', '#value' => $steps[$next_step_id]['next_label'], '#button_type' => 'primary', '#submit' => ['::submitForm'], ]; if ($has_previous_step) { $label = $steps[$previous_step_id]['previous_label']; $actions['next']['#suffix'] = Link::createFromRoute($label, 'acm_checkout.form', [ 'step' => $previous_step_id, ])->toString(); } } return $actions; }
[ "protected", "function", "actions", "(", "array", "$", "form", ",", "FormStateInterface", "$", "form_state", ")", "{", "$", "steps", "=", "$", "this", "->", "getVisibleSteps", "(", ")", ";", "$", "next_step_id", "=", "$", "this", "->", "getNextStepId", "(", ")", ";", "$", "previous_step_id", "=", "$", "this", "->", "getPreviousStepId", "(", ")", ";", "$", "has_next_step", "=", "$", "next_step_id", "&&", "isset", "(", "$", "steps", "[", "$", "next_step_id", "]", "[", "'next_label'", "]", ")", ";", "$", "has_previous_step", "=", "$", "previous_step_id", "&&", "isset", "(", "$", "steps", "[", "$", "previous_step_id", "]", "[", "'previous_label'", "]", ")", ";", "$", "actions", "=", "[", "'#type'", "=>", "'actions'", ",", "'#access'", "=>", "$", "has_next_step", ",", "]", ";", "if", "(", "$", "has_next_step", ")", "{", "$", "actions", "[", "'next'", "]", "=", "[", "'#type'", "=>", "'submit'", ",", "'#value'", "=>", "$", "steps", "[", "$", "next_step_id", "]", "[", "'next_label'", "]", ",", "'#button_type'", "=>", "'primary'", ",", "'#submit'", "=>", "[", "'::submitForm'", "]", ",", "]", ";", "if", "(", "$", "has_previous_step", ")", "{", "$", "label", "=", "$", "steps", "[", "$", "previous_step_id", "]", "[", "'previous_label'", "]", ";", "$", "actions", "[", "'next'", "]", "[", "'#suffix'", "]", "=", "Link", "::", "createFromRoute", "(", "$", "label", ",", "'acm_checkout.form'", ",", "[", "'step'", "=>", "$", "previous_step_id", ",", "]", ")", "->", "toString", "(", ")", ";", "}", "}", "return", "$", "actions", ";", "}" ]
Builds the actions element for the current form. @param array $form The current form. @param \Drupal\Core\Form\FormStateInterface $form_state The current form state. @return array The actions element.
[ "Builds", "the", "actions", "element", "for", "the", "current", "form", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutFlow/CheckoutFlowBase.php#L390-L419
train
acquia/commerce-manager
modules/acm_customer/src/Plugin/CustomerForm/Profile.php
Profile.addEditButton
public function addEditButton(array &$field, $field_name) { $field['#buttons']['edit'] = [ '#type' => 'link', '#title' => $this->t('Edit'), '#url' => Url::fromRoute('acm_customer.view_page', [ 'page' => $this->getPageId(), 'action' => 'edit', 'id' => $field_name, ]), '#attributes' => [ 'class' => [ 'form-item__edit-button', ], ], ]; }
php
public function addEditButton(array &$field, $field_name) { $field['#buttons']['edit'] = [ '#type' => 'link', '#title' => $this->t('Edit'), '#url' => Url::fromRoute('acm_customer.view_page', [ 'page' => $this->getPageId(), 'action' => 'edit', 'id' => $field_name, ]), '#attributes' => [ 'class' => [ 'form-item__edit-button', ], ], ]; }
[ "public", "function", "addEditButton", "(", "array", "&", "$", "field", ",", "$", "field_name", ")", "{", "$", "field", "[", "'#buttons'", "]", "[", "'edit'", "]", "=", "[", "'#type'", "=>", "'link'", ",", "'#title'", "=>", "$", "this", "->", "t", "(", "'Edit'", ")", ",", "'#url'", "=>", "Url", "::", "fromRoute", "(", "'acm_customer.view_page'", ",", "[", "'page'", "=>", "$", "this", "->", "getPageId", "(", ")", ",", "'action'", "=>", "'edit'", ",", "'id'", "=>", "$", "field_name", ",", "]", ")", ",", "'#attributes'", "=>", "[", "'class'", "=>", "[", "'form-item__edit-button'", ",", "]", ",", "]", ",", "]", ";", "}" ]
Adds an edit button to a form field. @param array $field The form field. @param string $field_name The name of the form field.
[ "Adds", "an", "edit", "button", "to", "a", "form", "field", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Plugin/CustomerForm/Profile.php#L144-L159
train
acquia/commerce-manager
modules/acm_customer/src/Plugin/CustomerForm/Profile.php
Profile.addSaveButtons
public function addSaveButtons(array &$field, $field_name) { $field['#display_value'] = FALSE; $field['#buttons']['cancel'] = [ '#type' => 'link', '#title' => $this->t('Cancel'), '#url' => Url::fromRoute('acm_customer.view_page', [ 'page' => $this->getPageId(), ]), '#attributes' => [ 'class' => [ 'form-item__cancel-button', ], ], ]; $field['#buttons']['save'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#submit' => ['::submitForm'], '#attributes' => [ 'class' => [ 'form-item__save-button', ], ], ]; }
php
public function addSaveButtons(array &$field, $field_name) { $field['#display_value'] = FALSE; $field['#buttons']['cancel'] = [ '#type' => 'link', '#title' => $this->t('Cancel'), '#url' => Url::fromRoute('acm_customer.view_page', [ 'page' => $this->getPageId(), ]), '#attributes' => [ 'class' => [ 'form-item__cancel-button', ], ], ]; $field['#buttons']['save'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#submit' => ['::submitForm'], '#attributes' => [ 'class' => [ 'form-item__save-button', ], ], ]; }
[ "public", "function", "addSaveButtons", "(", "array", "&", "$", "field", ",", "$", "field_name", ")", "{", "$", "field", "[", "'#display_value'", "]", "=", "FALSE", ";", "$", "field", "[", "'#buttons'", "]", "[", "'cancel'", "]", "=", "[", "'#type'", "=>", "'link'", ",", "'#title'", "=>", "$", "this", "->", "t", "(", "'Cancel'", ")", ",", "'#url'", "=>", "Url", "::", "fromRoute", "(", "'acm_customer.view_page'", ",", "[", "'page'", "=>", "$", "this", "->", "getPageId", "(", ")", ",", "]", ")", ",", "'#attributes'", "=>", "[", "'class'", "=>", "[", "'form-item__cancel-button'", ",", "]", ",", "]", ",", "]", ";", "$", "field", "[", "'#buttons'", "]", "[", "'save'", "]", "=", "[", "'#type'", "=>", "'submit'", ",", "'#value'", "=>", "$", "this", "->", "t", "(", "'Save'", ")", ",", "'#submit'", "=>", "[", "'::submitForm'", "]", ",", "'#attributes'", "=>", "[", "'class'", "=>", "[", "'form-item__save-button'", ",", "]", ",", "]", ",", "]", ";", "}" ]
Adds a save and cancel button to a form field. @param array $field The form field. @param string $field_name The name of the form field.
[ "Adds", "a", "save", "and", "cancel", "button", "to", "a", "form", "field", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_customer/src/Plugin/CustomerForm/Profile.php#L169-L193
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminAction.php
AdminAction.init
public function init(RequestInterface $request) { if (!session_id()) { session_cache_limiter(false); session_start(); } $this->setDataFromRequest($request); $this->authRedirect($request); return parent::init($request); }
php
public function init(RequestInterface $request) { if (!session_id()) { session_cache_limiter(false); session_start(); } $this->setDataFromRequest($request); $this->authRedirect($request); return parent::init($request); }
[ "public", "function", "init", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "!", "session_id", "(", ")", ")", "{", "session_cache_limiter", "(", "false", ")", ";", "session_start", "(", ")", ";", "}", "$", "this", "->", "setDataFromRequest", "(", "$", "request", ")", ";", "$", "this", "->", "authRedirect", "(", "$", "request", ")", ";", "return", "parent", "::", "init", "(", "$", "request", ")", ";", "}" ]
Action's init method is called automatically from `charcoal-app`'s Action Route. For admin actions, initializations is: - to start a session, if necessary - to authenticate - to initialize the action data with the PSR Request object @param RequestInterface $request The request to initialize. @return boolean @see \Charcoal\App\Route\TemplateRoute::__invoke()
[ "Action", "s", "init", "method", "is", "called", "automatically", "from", "charcoal", "-", "app", "s", "Action", "Route", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminAction.php#L90-L101
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminAction.php
AdminAction.recaptchaEnabled
public function recaptchaEnabled() { $recaptcha = $this->apiConfig('google.recaptcha'); if (empty($recaptcha) || (isset($recaptcha['active']) && $recaptcha['active'] === false)) { return false; } return (!empty($recaptcha['public_key']) || !empty($recaptcha['key'])) && (!empty($recaptcha['private_key']) || !empty($recaptcha['secret'])); }
php
public function recaptchaEnabled() { $recaptcha = $this->apiConfig('google.recaptcha'); if (empty($recaptcha) || (isset($recaptcha['active']) && $recaptcha['active'] === false)) { return false; } return (!empty($recaptcha['public_key']) || !empty($recaptcha['key'])) && (!empty($recaptcha['private_key']) || !empty($recaptcha['secret'])); }
[ "public", "function", "recaptchaEnabled", "(", ")", "{", "$", "recaptcha", "=", "$", "this", "->", "apiConfig", "(", "'google.recaptcha'", ")", ";", "if", "(", "empty", "(", "$", "recaptcha", ")", "||", "(", "isset", "(", "$", "recaptcha", "[", "'active'", "]", ")", "&&", "$", "recaptcha", "[", "'active'", "]", "===", "false", ")", ")", "{", "return", "false", ";", "}", "return", "(", "!", "empty", "(", "$", "recaptcha", "[", "'public_key'", "]", ")", "||", "!", "empty", "(", "$", "recaptcha", "[", "'key'", "]", ")", ")", "&&", "(", "!", "empty", "(", "$", "recaptcha", "[", "'private_key'", "]", ")", "||", "!", "empty", "(", "$", "recaptcha", "[", "'secret'", "]", ")", ")", ";", "}" ]
Determine if a CAPTCHA test is available. For example, the "Login", "Lost Password", and "Reset Password" templates can render the CAPTCHA test. @see AdminTemplate::recaptchaEnabled() Duplicate @return boolean
[ "Determine", "if", "a", "CAPTCHA", "test", "is", "available", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminAction.php#L252-L262
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminAction.php
AdminAction.recaptchaSecretKey
public function recaptchaSecretKey() { $recaptcha = $this->apiConfig('google.recaptcha'); if (!empty($recaptcha['private_key'])) { return $recaptcha['private_key']; } elseif (!empty($recaptcha['secret'])) { return $recaptcha['secret']; } return null; }
php
public function recaptchaSecretKey() { $recaptcha = $this->apiConfig('google.recaptcha'); if (!empty($recaptcha['private_key'])) { return $recaptcha['private_key']; } elseif (!empty($recaptcha['secret'])) { return $recaptcha['secret']; } return null; }
[ "public", "function", "recaptchaSecretKey", "(", ")", "{", "$", "recaptcha", "=", "$", "this", "->", "apiConfig", "(", "'google.recaptcha'", ")", ";", "if", "(", "!", "empty", "(", "$", "recaptcha", "[", "'private_key'", "]", ")", ")", "{", "return", "$", "recaptcha", "[", "'private_key'", "]", ";", "}", "elseif", "(", "!", "empty", "(", "$", "recaptcha", "[", "'secret'", "]", ")", ")", "{", "return", "$", "recaptcha", "[", "'secret'", "]", ";", "}", "return", "null", ";", "}" ]
Retrieve the Google reCAPTCHA secret key. @throws RuntimeException If Google reCAPTCHA is required but not configured. @return string|null
[ "Retrieve", "the", "Google", "reCAPTCHA", "secret", "key", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminAction.php#L270-L281
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminAction.php
AdminAction.validateCaptcha
protected function validateCaptcha($token) { if (empty($token)) { throw new RuntimeException('Google reCAPTCHA response parameter is invalid or malformed.'); } $secret = $this->recaptchaSecretKey(); if (empty($secret)) { throw new RuntimeException('Google reCAPTCHA [apis.google.recaptcha.private_key] is not configured.'); } $data = [ 'secret' => $secret, 'response' => $token, ]; if (isset($_SERVER['REMOTE_ADDR'])) { $data['remoteip'] = $_SERVER['REMOTE_ADDR']; } $query = http_build_query($data); $url = static::GOOGLE_RECAPTCHA_SERVER_URL.'?'.$query; $this->logger->debug(sprintf('Verifying reCAPTCHA user response: %s', $url)); /** * @todo Use Guzzle */ $result = file_get_contents($url); $result = (array)json_decode($result, true); $this->recaptchaLastToken = $token; $this->recaptchaLastResult = $result; return isset($result['success']) && (bool)$result['success']; }
php
protected function validateCaptcha($token) { if (empty($token)) { throw new RuntimeException('Google reCAPTCHA response parameter is invalid or malformed.'); } $secret = $this->recaptchaSecretKey(); if (empty($secret)) { throw new RuntimeException('Google reCAPTCHA [apis.google.recaptcha.private_key] is not configured.'); } $data = [ 'secret' => $secret, 'response' => $token, ]; if (isset($_SERVER['REMOTE_ADDR'])) { $data['remoteip'] = $_SERVER['REMOTE_ADDR']; } $query = http_build_query($data); $url = static::GOOGLE_RECAPTCHA_SERVER_URL.'?'.$query; $this->logger->debug(sprintf('Verifying reCAPTCHA user response: %s', $url)); /** * @todo Use Guzzle */ $result = file_get_contents($url); $result = (array)json_decode($result, true); $this->recaptchaLastToken = $token; $this->recaptchaLastResult = $result; return isset($result['success']) && (bool)$result['success']; }
[ "protected", "function", "validateCaptcha", "(", "$", "token", ")", "{", "if", "(", "empty", "(", "$", "token", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Google reCAPTCHA response parameter is invalid or malformed.'", ")", ";", "}", "$", "secret", "=", "$", "this", "->", "recaptchaSecretKey", "(", ")", ";", "if", "(", "empty", "(", "$", "secret", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Google reCAPTCHA [apis.google.recaptcha.private_key] is not configured.'", ")", ";", "}", "$", "data", "=", "[", "'secret'", "=>", "$", "secret", ",", "'response'", "=>", "$", "token", ",", "]", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ")", ")", "{", "$", "data", "[", "'remoteip'", "]", "=", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ";", "}", "$", "query", "=", "http_build_query", "(", "$", "data", ")", ";", "$", "url", "=", "static", "::", "GOOGLE_RECAPTCHA_SERVER_URL", ".", "'?'", ".", "$", "query", ";", "$", "this", "->", "logger", "->", "debug", "(", "sprintf", "(", "'Verifying reCAPTCHA user response: %s'", ",", "$", "url", ")", ")", ";", "/**\n * @todo Use Guzzle\n */", "$", "result", "=", "file_get_contents", "(", "$", "url", ")", ";", "$", "result", "=", "(", "array", ")", "json_decode", "(", "$", "result", ",", "true", ")", ";", "$", "this", "->", "recaptchaLastToken", "=", "$", "token", ";", "$", "this", "->", "recaptchaLastResult", "=", "$", "result", ";", "return", "isset", "(", "$", "result", "[", "'success'", "]", ")", "&&", "(", "bool", ")", "$", "result", "[", "'success'", "]", ";", "}" ]
Validate a Google reCAPTCHA user response. @todo {@link https://github.com/mcaskill/charcoal-recaptcha Implement CAPTCHA validation as a service}. @link https://developers.google.com/recaptcha/docs/verify @param string $token A user response token provided by reCAPTCHA. @throws RuntimeException If Google reCAPTCHA is not configured. @return boolean Returns TRUE if the user response is valid, FALSE if it is invalid.
[ "Validate", "a", "Google", "reCAPTCHA", "user", "response", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminAction.php#L302-L337
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminAction.php
AdminAction.validateCaptchaFromRequest
protected function validateCaptchaFromRequest(RequestInterface $request, ResponseInterface &$response = null) { $token = $request->getParam('g-recaptcha-response', false); if (empty($token)) { if ($response !== null) { $this->addFeedback('error', $this->translator()->translate('Missing CAPTCHA response.')); $this->setSuccess(false); $response = $response->withStatus(400); } return false; } $result = $this->validateCaptcha($token); if ($result === false && $response !== null) { $this->addFeedback('error', $this->translator()->translate('Invalid or malformed CAPTCHA response.')); $this->setSuccess(false); $response = $response->withStatus(400); } return $result; }
php
protected function validateCaptchaFromRequest(RequestInterface $request, ResponseInterface &$response = null) { $token = $request->getParam('g-recaptcha-response', false); if (empty($token)) { if ($response !== null) { $this->addFeedback('error', $this->translator()->translate('Missing CAPTCHA response.')); $this->setSuccess(false); $response = $response->withStatus(400); } return false; } $result = $this->validateCaptcha($token); if ($result === false && $response !== null) { $this->addFeedback('error', $this->translator()->translate('Invalid or malformed CAPTCHA response.')); $this->setSuccess(false); $response = $response->withStatus(400); } return $result; }
[ "protected", "function", "validateCaptchaFromRequest", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "&", "$", "response", "=", "null", ")", "{", "$", "token", "=", "$", "request", "->", "getParam", "(", "'g-recaptcha-response'", ",", "false", ")", ";", "if", "(", "empty", "(", "$", "token", ")", ")", "{", "if", "(", "$", "response", "!==", "null", ")", "{", "$", "this", "->", "addFeedback", "(", "'error'", ",", "$", "this", "->", "translator", "(", ")", "->", "translate", "(", "'Missing CAPTCHA response.'", ")", ")", ";", "$", "this", "->", "setSuccess", "(", "false", ")", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "400", ")", ";", "}", "return", "false", ";", "}", "$", "result", "=", "$", "this", "->", "validateCaptcha", "(", "$", "token", ")", ";", "if", "(", "$", "result", "===", "false", "&&", "$", "response", "!==", "null", ")", "{", "$", "this", "->", "addFeedback", "(", "'error'", ",", "$", "this", "->", "translator", "(", ")", "->", "translate", "(", "'Invalid or malformed CAPTCHA response.'", ")", ")", ";", "$", "this", "->", "setSuccess", "(", "false", ")", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "400", ")", ";", "}", "return", "$", "result", ";", "}" ]
Validate a Google reCAPTCHA user response from a PSR Request object. @param RequestInterface $request A PSR-7 compatible Request instance. @param ResponseInterface|null $response A PSR-7 compatible Response instance. If $response is provided and challenge fails, then it is replaced with a new Response object that represents a client error. @return boolean Returns TRUE if the user response is valid, FALSE if it is invalid.
[ "Validate", "a", "Google", "reCAPTCHA", "user", "response", "from", "a", "PSR", "Request", "object", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminAction.php#L348-L371
train
acquia/commerce-manager
modules/acm/src/Controller/CommerceUserController.php
CommerceUserController.resetPass
public function resetPass($email, $timestamp, $hash) { $this->session->set('pass_reset_hash', $hash); $this->session->set('pass_reset_timeout', $timestamp); return $this->redirect( 'acm.external_user_password_reset_form', ['email' => $email] ); }
php
public function resetPass($email, $timestamp, $hash) { $this->session->set('pass_reset_hash', $hash); $this->session->set('pass_reset_timeout', $timestamp); return $this->redirect( 'acm.external_user_password_reset_form', ['email' => $email] ); }
[ "public", "function", "resetPass", "(", "$", "email", ",", "$", "timestamp", ",", "$", "hash", ")", "{", "$", "this", "->", "session", "->", "set", "(", "'pass_reset_hash'", ",", "$", "hash", ")", ";", "$", "this", "->", "session", "->", "set", "(", "'pass_reset_timeout'", ",", "$", "timestamp", ")", ";", "return", "$", "this", "->", "redirect", "(", "'acm.external_user_password_reset_form'", ",", "[", "'email'", "=>", "$", "email", "]", ")", ";", "}" ]
Redirects to the user password reset form. In order to never disclose a reset link via a referrer header this controller must always return a redirect response. @param string $email The base64 encoded email address of the user requesting a password reset. @param int $timestamp The current timestamp. @param string $hash Login link hash. @return \Symfony\Component\HttpFoundation\RedirectResponse The redirect response.
[ "Redirects", "to", "the", "user", "password", "reset", "form", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Controller/CommerceUserController.php#L135-L142
train
acquia/commerce-manager
modules/acm/src/Controller/CommerceUserController.php
CommerceUserController.getResetPassForm
public function getResetPassForm($email) { $timestamp = $this->session->get('pass_reset_timeout'); $hash = $this->session->get('pass_reset_hash'); // As soon as the session variables are used they are removed to prevent the // hash and timestamp from being leaked unexpectedly. This could occur if // the user does not click on the log in button on the form. $this->session->remove('pass_reset_timeout'); $this->session->remove('pass_reset_hash'); if (!$hash || !$timestamp) { throw new AccessDeniedHttpException(); } // Time out, in seconds, until login URL expires. $timeout = $this->config('user.settings')->get('password_reset_timeout'); $expiration_date = $this->dateFormatter->format($timestamp + $timeout); return $this->formBuilder()->getForm(CommerceUserPasswordResetForm::class, $email, $expiration_date, $timestamp, $hash); }
php
public function getResetPassForm($email) { $timestamp = $this->session->get('pass_reset_timeout'); $hash = $this->session->get('pass_reset_hash'); // As soon as the session variables are used they are removed to prevent the // hash and timestamp from being leaked unexpectedly. This could occur if // the user does not click on the log in button on the form. $this->session->remove('pass_reset_timeout'); $this->session->remove('pass_reset_hash'); if (!$hash || !$timestamp) { throw new AccessDeniedHttpException(); } // Time out, in seconds, until login URL expires. $timeout = $this->config('user.settings')->get('password_reset_timeout'); $expiration_date = $this->dateFormatter->format($timestamp + $timeout); return $this->formBuilder()->getForm(CommerceUserPasswordResetForm::class, $email, $expiration_date, $timestamp, $hash); }
[ "public", "function", "getResetPassForm", "(", "$", "email", ")", "{", "$", "timestamp", "=", "$", "this", "->", "session", "->", "get", "(", "'pass_reset_timeout'", ")", ";", "$", "hash", "=", "$", "this", "->", "session", "->", "get", "(", "'pass_reset_hash'", ")", ";", "// As soon as the session variables are used they are removed to prevent the", "// hash and timestamp from being leaked unexpectedly. This could occur if", "// the user does not click on the log in button on the form.", "$", "this", "->", "session", "->", "remove", "(", "'pass_reset_timeout'", ")", ";", "$", "this", "->", "session", "->", "remove", "(", "'pass_reset_hash'", ")", ";", "if", "(", "!", "$", "hash", "||", "!", "$", "timestamp", ")", "{", "throw", "new", "AccessDeniedHttpException", "(", ")", ";", "}", "// Time out, in seconds, until login URL expires.", "$", "timeout", "=", "$", "this", "->", "config", "(", "'user.settings'", ")", "->", "get", "(", "'password_reset_timeout'", ")", ";", "$", "expiration_date", "=", "$", "this", "->", "dateFormatter", "->", "format", "(", "$", "timestamp", "+", "$", "timeout", ")", ";", "return", "$", "this", "->", "formBuilder", "(", ")", "->", "getForm", "(", "CommerceUserPasswordResetForm", "::", "class", ",", "$", "email", ",", "$", "expiration_date", ",", "$", "timestamp", ",", "$", "hash", ")", ";", "}" ]
Returns the user password reset form. @param string $email The base64 encoded email address of the user requesting a password reset. @return array|\Symfony\Component\HttpFoundation\RedirectResponse The form structure or a redirect response. @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException If the pass_reset_timeout or pass_reset_hash are not available in the session. Or if $uid is for a blocked user or invalid user ID.
[ "Returns", "the", "user", "password", "reset", "form", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Controller/CommerceUserController.php#L157-L175
train
acquia/commerce-manager
modules/acm/src/Controller/CommerceUserController.php
CommerceUserController.resetPassLogin
public function resetPassLogin(Request $request, $email, $timestamp, $hash) { $user = NULL; $email = base64_decode($email); try { $user = $this->apiWrapper->getCustomer($email); } catch (\Exception $e) { } // Verify that the user exists and is active. if (!$user) { // Blocked or invalid user, so deny access. The parameters will be in the // watchdog's URL for the administrator to check. throw new AccessDeniedHttpException(); } // Wrap user in CommerceUserSession. $account = new CommerceUserSession($user); // The current user is not logged in, so check the parameters. $current = REQUEST_TIME; // Time out, in seconds, until login URL expires. $timeout = $this->config('user.settings')->get('password_reset_timeout'); if ($current - $timestamp > $timeout) { drupal_set_message($this->t('you have tried to use a one-time password reset link that has expired. Please request a new one using the form below.'), 'error'); return $this->redirect('acm.external_user_password'); } elseif (($timestamp <= $current) && Crypt::hashEquals($hash, acm_commerce_user_pass_rehash($account, $timestamp))) { $password_values = $request->get('new_password'); $pass1 = trim($password_values['pass1']); $pass2 = trim($password_values['pass2']); if (strlen($pass1) > 0 || strlen($pass2) > 0) { if (strcmp($pass1, $pass2)) { // Passwords don't match, return back to the reset password page so // they can correct. drupal_set_message($this->t('The passwords you entered do not match.'), 'error'); return $this->redirect( 'acm.external_user_password_reset', [ 'email' => base64_encode($email), 'timestamp' => $timestamp, 'hash' => $hash, ] ); } } $updated_user = FALSE; try { // Update customer's password. $updated_user = $this->apiWrapper->updateCustomer($user, ['password' => $pass1]); // Generate and store the access token and log the user in. if ($token = $this->userAuth->authenticate($email, $pass1)) { $this->commerceUserManager->setAccessToken($token); // This will retrieve and store the account with the new access token. $this->commerceUserManager->getAccount(); } } catch (\Exception $e) { } if ($updated_user) { drupal_set_message($this->t('Your password has been updated.')); return $this->redirect('acm_customer.view_page'); } else { drupal_set_message($this->t('There was an issue updating your password.'), 'error'); return $this->redirect('acm.external_user_password'); } } drupal_set_message($this->t('You have tried to use a one-time password reset link that has either been used or is no longer valid. Please request a new one using the form below.'), 'error'); return $this->redirect('acm.external_user_password'); }
php
public function resetPassLogin(Request $request, $email, $timestamp, $hash) { $user = NULL; $email = base64_decode($email); try { $user = $this->apiWrapper->getCustomer($email); } catch (\Exception $e) { } // Verify that the user exists and is active. if (!$user) { // Blocked or invalid user, so deny access. The parameters will be in the // watchdog's URL for the administrator to check. throw new AccessDeniedHttpException(); } // Wrap user in CommerceUserSession. $account = new CommerceUserSession($user); // The current user is not logged in, so check the parameters. $current = REQUEST_TIME; // Time out, in seconds, until login URL expires. $timeout = $this->config('user.settings')->get('password_reset_timeout'); if ($current - $timestamp > $timeout) { drupal_set_message($this->t('you have tried to use a one-time password reset link that has expired. Please request a new one using the form below.'), 'error'); return $this->redirect('acm.external_user_password'); } elseif (($timestamp <= $current) && Crypt::hashEquals($hash, acm_commerce_user_pass_rehash($account, $timestamp))) { $password_values = $request->get('new_password'); $pass1 = trim($password_values['pass1']); $pass2 = trim($password_values['pass2']); if (strlen($pass1) > 0 || strlen($pass2) > 0) { if (strcmp($pass1, $pass2)) { // Passwords don't match, return back to the reset password page so // they can correct. drupal_set_message($this->t('The passwords you entered do not match.'), 'error'); return $this->redirect( 'acm.external_user_password_reset', [ 'email' => base64_encode($email), 'timestamp' => $timestamp, 'hash' => $hash, ] ); } } $updated_user = FALSE; try { // Update customer's password. $updated_user = $this->apiWrapper->updateCustomer($user, ['password' => $pass1]); // Generate and store the access token and log the user in. if ($token = $this->userAuth->authenticate($email, $pass1)) { $this->commerceUserManager->setAccessToken($token); // This will retrieve and store the account with the new access token. $this->commerceUserManager->getAccount(); } } catch (\Exception $e) { } if ($updated_user) { drupal_set_message($this->t('Your password has been updated.')); return $this->redirect('acm_customer.view_page'); } else { drupal_set_message($this->t('There was an issue updating your password.'), 'error'); return $this->redirect('acm.external_user_password'); } } drupal_set_message($this->t('You have tried to use a one-time password reset link that has either been used or is no longer valid. Please request a new one using the form below.'), 'error'); return $this->redirect('acm.external_user_password'); }
[ "public", "function", "resetPassLogin", "(", "Request", "$", "request", ",", "$", "email", ",", "$", "timestamp", ",", "$", "hash", ")", "{", "$", "user", "=", "NULL", ";", "$", "email", "=", "base64_decode", "(", "$", "email", ")", ";", "try", "{", "$", "user", "=", "$", "this", "->", "apiWrapper", "->", "getCustomer", "(", "$", "email", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "// Verify that the user exists and is active.", "if", "(", "!", "$", "user", ")", "{", "// Blocked or invalid user, so deny access. The parameters will be in the", "// watchdog's URL for the administrator to check.", "throw", "new", "AccessDeniedHttpException", "(", ")", ";", "}", "// Wrap user in CommerceUserSession.", "$", "account", "=", "new", "CommerceUserSession", "(", "$", "user", ")", ";", "// The current user is not logged in, so check the parameters.", "$", "current", "=", "REQUEST_TIME", ";", "// Time out, in seconds, until login URL expires.", "$", "timeout", "=", "$", "this", "->", "config", "(", "'user.settings'", ")", "->", "get", "(", "'password_reset_timeout'", ")", ";", "if", "(", "$", "current", "-", "$", "timestamp", ">", "$", "timeout", ")", "{", "drupal_set_message", "(", "$", "this", "->", "t", "(", "'you have tried to use a one-time password reset link that has expired. Please request a new one using the form below.'", ")", ",", "'error'", ")", ";", "return", "$", "this", "->", "redirect", "(", "'acm.external_user_password'", ")", ";", "}", "elseif", "(", "(", "$", "timestamp", "<=", "$", "current", ")", "&&", "Crypt", "::", "hashEquals", "(", "$", "hash", ",", "acm_commerce_user_pass_rehash", "(", "$", "account", ",", "$", "timestamp", ")", ")", ")", "{", "$", "password_values", "=", "$", "request", "->", "get", "(", "'new_password'", ")", ";", "$", "pass1", "=", "trim", "(", "$", "password_values", "[", "'pass1'", "]", ")", ";", "$", "pass2", "=", "trim", "(", "$", "password_values", "[", "'pass2'", "]", ")", ";", "if", "(", "strlen", "(", "$", "pass1", ")", ">", "0", "||", "strlen", "(", "$", "pass2", ")", ">", "0", ")", "{", "if", "(", "strcmp", "(", "$", "pass1", ",", "$", "pass2", ")", ")", "{", "// Passwords don't match, return back to the reset password page so", "// they can correct.", "drupal_set_message", "(", "$", "this", "->", "t", "(", "'The passwords you entered do not match.'", ")", ",", "'error'", ")", ";", "return", "$", "this", "->", "redirect", "(", "'acm.external_user_password_reset'", ",", "[", "'email'", "=>", "base64_encode", "(", "$", "email", ")", ",", "'timestamp'", "=>", "$", "timestamp", ",", "'hash'", "=>", "$", "hash", ",", "]", ")", ";", "}", "}", "$", "updated_user", "=", "FALSE", ";", "try", "{", "// Update customer's password.", "$", "updated_user", "=", "$", "this", "->", "apiWrapper", "->", "updateCustomer", "(", "$", "user", ",", "[", "'password'", "=>", "$", "pass1", "]", ")", ";", "// Generate and store the access token and log the user in.", "if", "(", "$", "token", "=", "$", "this", "->", "userAuth", "->", "authenticate", "(", "$", "email", ",", "$", "pass1", ")", ")", "{", "$", "this", "->", "commerceUserManager", "->", "setAccessToken", "(", "$", "token", ")", ";", "// This will retrieve and store the account with the new access token.", "$", "this", "->", "commerceUserManager", "->", "getAccount", "(", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "if", "(", "$", "updated_user", ")", "{", "drupal_set_message", "(", "$", "this", "->", "t", "(", "'Your password has been updated.'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "'acm_customer.view_page'", ")", ";", "}", "else", "{", "drupal_set_message", "(", "$", "this", "->", "t", "(", "'There was an issue updating your password.'", ")", ",", "'error'", ")", ";", "return", "$", "this", "->", "redirect", "(", "'acm.external_user_password'", ")", ";", "}", "}", "drupal_set_message", "(", "$", "this", "->", "t", "(", "'You have tried to use a one-time password reset link that has either been used or is no longer valid. Please request a new one using the form below.'", ")", ",", "'error'", ")", ";", "return", "$", "this", "->", "redirect", "(", "'acm.external_user_password'", ")", ";", "}" ]
Reset password and log in. Validates user, hash, and timestamp; logs the user in and resets password if correct. @param \Symfony\Component\HttpFoundation\Request $request The request. @param int $email The base64 encoded email address of the user requesting a password reset. @param int $timestamp The current timestamp. @param string $hash Login link hash. @return \Symfony\Component\HttpFoundation\RedirectResponse Returns a redirect to the user edit form if the information is correct. If the information is incorrect redirects to 'user.pass' route with a message for the user. @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException If $uid is for a blocked user or invalid user ID.
[ "Reset", "password", "and", "log", "in", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Controller/CommerceUserController.php#L200-L274
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/Selectize/TagsInput.php
TagsInput.setSelectizeOptions
public function setSelectizeOptions(array $settings) { $this->selectizeOptions = array_merge( $this->defaultSelectizeOptions(), $this->parseSelectizeOptions($settings) ); return $this; }
php
public function setSelectizeOptions(array $settings) { $this->selectizeOptions = array_merge( $this->defaultSelectizeOptions(), $this->parseSelectizeOptions($settings) ); return $this; }
[ "public", "function", "setSelectizeOptions", "(", "array", "$", "settings", ")", "{", "$", "this", "->", "selectizeOptions", "=", "array_merge", "(", "$", "this", "->", "defaultSelectizeOptions", "(", ")", ",", "$", "this", "->", "parseSelectizeOptions", "(", "$", "settings", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set the selectize picker's options. This method overwrites existing helpers. @param array $settings The selectize picker options. @return TagsInput Chainable
[ "Set", "the", "selectize", "picker", "s", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/Selectize/TagsInput.php#L134-L142
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/Selectize/TagsInput.php
TagsInput.selectizeOptions
public function selectizeOptions() { if ($this->selectizeOptions === null) { $this->selectizeOptions = $this->defaultSelectizeOptions(); } return $this->selectizeOptions; }
php
public function selectizeOptions() { if ($this->selectizeOptions === null) { $this->selectizeOptions = $this->defaultSelectizeOptions(); } return $this->selectizeOptions; }
[ "public", "function", "selectizeOptions", "(", ")", "{", "if", "(", "$", "this", "->", "selectizeOptions", "===", "null", ")", "{", "$", "this", "->", "selectizeOptions", "=", "$", "this", "->", "defaultSelectizeOptions", "(", ")", ";", "}", "return", "$", "this", "->", "selectizeOptions", ";", "}" ]
Retrieve the selectize picker's options. @return array
[ "Retrieve", "the", "selectize", "picker", "s", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/Selectize/TagsInput.php#L195-L202
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/SecondaryMenu/SecondaryMenuGroupTrait.php
SecondaryMenuGroupTrait.isSelected
public function isSelected($flag = null) { if ($flag !== null) { $this->isSelected = !!$flag; $this->setCollapsed(!$flag); } return $this->isSelected; }
php
public function isSelected($flag = null) { if ($flag !== null) { $this->isSelected = !!$flag; $this->setCollapsed(!$flag); } return $this->isSelected; }
[ "public", "function", "isSelected", "(", "$", "flag", "=", "null", ")", "{", "if", "(", "$", "flag", "!==", "null", ")", "{", "$", "this", "->", "isSelected", "=", "!", "!", "$", "flag", ";", "$", "this", "->", "setCollapsed", "(", "!", "$", "flag", ")", ";", "}", "return", "$", "this", "->", "isSelected", ";", "}" ]
Set whether the item is selected or not. @param boolean|null $flag Whether the item is selected or not. @return boolean
[ "Set", "whether", "the", "item", "is", "selected", "or", "not", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/SecondaryMenu/SecondaryMenuGroupTrait.php#L333-L342
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/SecondaryMenu/SecondaryMenuGroupTrait.php
SecondaryMenuGroupTrait.collapsed
public function collapsed() { $collapsed = $this->collapsible(); if (is_bool($this->collapsed)) { $collapsed = $this->collapsed; } if (is_bool($this->isSelected())) { $collapsed = !$this->isSelected; } return $collapsed; }
php
public function collapsed() { $collapsed = $this->collapsible(); if (is_bool($this->collapsed)) { $collapsed = $this->collapsed; } if (is_bool($this->isSelected())) { $collapsed = !$this->isSelected; } return $collapsed; }
[ "public", "function", "collapsed", "(", ")", "{", "$", "collapsed", "=", "$", "this", "->", "collapsible", "(", ")", ";", "if", "(", "is_bool", "(", "$", "this", "->", "collapsed", ")", ")", "{", "$", "collapsed", "=", "$", "this", "->", "collapsed", ";", "}", "if", "(", "is_bool", "(", "$", "this", "->", "isSelected", "(", ")", ")", ")", "{", "$", "collapsed", "=", "!", "$", "this", "->", "isSelected", ";", "}", "return", "$", "collapsed", ";", "}" ]
Determine if the group is collapsed. @return boolean
[ "Determine", "if", "the", "group", "is", "collapsed", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/SecondaryMenu/SecondaryMenuGroupTrait.php#L382-L395
train
acquia/commerce-manager
modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Variant.php
Variant.buildAttributeRow
public function buildAttributeRow($key, array $group = []) { $weight = isset($group['weight']) ? $group['weight'] : 0; $row = []; $row['enabled'] = [ '#type' => 'checkbox', '#default_value' => isset($group['enabled']) ? $group['enabled'] : 0, ]; $row['name'] = [ '#plain_text' => $key, ]; $row['label'] = [ '#type' => 'textfield', '#default_value' => isset($group['label']) ? $group['label'] : '', ]; $row['weight'] = [ '#type' => 'weight', '#title' => t('Weight'), '#title_display' => 'invisible', '#default_value' => $weight, '#attributes' => ['class' => ['weight']], ]; $row['#attributes']['class'][] = 'draggable'; return $row; }
php
public function buildAttributeRow($key, array $group = []) { $weight = isset($group['weight']) ? $group['weight'] : 0; $row = []; $row['enabled'] = [ '#type' => 'checkbox', '#default_value' => isset($group['enabled']) ? $group['enabled'] : 0, ]; $row['name'] = [ '#plain_text' => $key, ]; $row['label'] = [ '#type' => 'textfield', '#default_value' => isset($group['label']) ? $group['label'] : '', ]; $row['weight'] = [ '#type' => 'weight', '#title' => t('Weight'), '#title_display' => 'invisible', '#default_value' => $weight, '#attributes' => ['class' => ['weight']], ]; $row['#attributes']['class'][] = 'draggable'; return $row; }
[ "public", "function", "buildAttributeRow", "(", "$", "key", ",", "array", "$", "group", "=", "[", "]", ")", "{", "$", "weight", "=", "isset", "(", "$", "group", "[", "'weight'", "]", ")", "?", "$", "group", "[", "'weight'", "]", ":", "0", ";", "$", "row", "=", "[", "]", ";", "$", "row", "[", "'enabled'", "]", "=", "[", "'#type'", "=>", "'checkbox'", ",", "'#default_value'", "=>", "isset", "(", "$", "group", "[", "'enabled'", "]", ")", "?", "$", "group", "[", "'enabled'", "]", ":", "0", ",", "]", ";", "$", "row", "[", "'name'", "]", "=", "[", "'#plain_text'", "=>", "$", "key", ",", "]", ";", "$", "row", "[", "'label'", "]", "=", "[", "'#type'", "=>", "'textfield'", ",", "'#default_value'", "=>", "isset", "(", "$", "group", "[", "'label'", "]", ")", "?", "$", "group", "[", "'label'", "]", ":", "''", ",", "]", ";", "$", "row", "[", "'weight'", "]", "=", "[", "'#type'", "=>", "'weight'", ",", "'#title'", "=>", "t", "(", "'Weight'", ")", ",", "'#title_display'", "=>", "'invisible'", ",", "'#default_value'", "=>", "$", "weight", ",", "'#attributes'", "=>", "[", "'class'", "=>", "[", "'weight'", "]", "]", ",", "]", ";", "$", "row", "[", "'#attributes'", "]", "[", "'class'", "]", "[", "]", "=", "'draggable'", ";", "return", "$", "row", ";", "}" ]
Builds a row for the attributes form. @param string $key The attribute name/key. @param array $group The saved attribute values. @return array A table form row render array.
[ "Builds", "a", "row", "for", "the", "attributes", "form", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Variant.php#L98-L126
train
acquia/commerce-manager
modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Variant.php
Variant.getConfiguredOptions
public function getConfiguredOptions(SKU $child) { $sku_type = SKUType::load($this->getPluginDefinition()['id']); $groups = $sku_type->getThirdPartySetting('acm_sku__variant', 'attribute_groups', []); $configured_options = []; $attributes = $child->attributes->getValue(); foreach ($attributes as $attribute) { if (empty($groups[$attribute['key']]['enabled'])) { continue; } $configured_options[] = $attribute['value']; } return $configured_options; }
php
public function getConfiguredOptions(SKU $child) { $sku_type = SKUType::load($this->getPluginDefinition()['id']); $groups = $sku_type->getThirdPartySetting('acm_sku__variant', 'attribute_groups', []); $configured_options = []; $attributes = $child->attributes->getValue(); foreach ($attributes as $attribute) { if (empty($groups[$attribute['key']]['enabled'])) { continue; } $configured_options[] = $attribute['value']; } return $configured_options; }
[ "public", "function", "getConfiguredOptions", "(", "SKU", "$", "child", ")", "{", "$", "sku_type", "=", "SKUType", "::", "load", "(", "$", "this", "->", "getPluginDefinition", "(", ")", "[", "'id'", "]", ")", ";", "$", "groups", "=", "$", "sku_type", "->", "getThirdPartySetting", "(", "'acm_sku__variant'", ",", "'attribute_groups'", ",", "[", "]", ")", ";", "$", "configured_options", "=", "[", "]", ";", "$", "attributes", "=", "$", "child", "->", "attributes", "->", "getValue", "(", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "if", "(", "empty", "(", "$", "groups", "[", "$", "attribute", "[", "'key'", "]", "]", "[", "'enabled'", "]", ")", ")", "{", "continue", ";", "}", "$", "configured_options", "[", "]", "=", "$", "attribute", "[", "'value'", "]", ";", "}", "return", "$", "configured_options", ";", "}" ]
Get the configured options for this SKU instance. @return array An array of the configured attributes for this SKU.
[ "Get", "the", "configured", "options", "for", "this", "SKU", "instance", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Variant.php#L543-L555
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/FormGroup/AclPermissions.php
AclPermissions.db
protected function db() { if (!isset($this->database)) { throw new RuntimeException(sprintf( 'Database Connection is not defined for "%s"', get_class($this) )); } return $this->database; }
php
protected function db() { if (!isset($this->database)) { throw new RuntimeException(sprintf( 'Database Connection is not defined for "%s"', get_class($this) )); } return $this->database; }
[ "protected", "function", "db", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "database", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Database Connection is not defined for \"%s\"'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "return", "$", "this", "->", "database", ";", "}" ]
Retrieve the database connection. @throws RuntimeException If the connection is undefined. @return PDO
[ "Retrieve", "the", "database", "connection", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/AclPermissions.php#L127-L137
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/FormGroup/AclPermissions.php
AclPermissions.adminAcl
protected function adminAcl() { if (!isset($this->aclManager)) { throw new RuntimeException(sprintf( 'ACL Manager is not defined for "%s"', get_class($this) )); } return $this->aclManager; }
php
protected function adminAcl() { if (!isset($this->aclManager)) { throw new RuntimeException(sprintf( 'ACL Manager is not defined for "%s"', get_class($this) )); } return $this->aclManager; }
[ "protected", "function", "adminAcl", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "aclManager", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'ACL Manager is not defined for \"%s\"'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "return", "$", "this", "->", "aclManager", ";", "}" ]
Retrieve the ACL manager. @throws RuntimeException If the manager is undefined. @return AclManager
[ "Retrieve", "the", "ACL", "manager", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/FormGroup/AclPermissions.php#L145-L155
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/CollectionContainerTrait.php
CollectionContainerTrait.modelFactory
protected function modelFactory() { if ($this->modelFactory === null) { throw new Exception(sprintf( 'Model Factory is not defined for "%s"', get_class($this) )); } return $this->modelFactory; }
php
protected function modelFactory() { if ($this->modelFactory === null) { throw new Exception(sprintf( 'Model Factory is not defined for "%s"', get_class($this) )); } return $this->modelFactory; }
[ "protected", "function", "modelFactory", "(", ")", "{", "if", "(", "$", "this", "->", "modelFactory", "===", "null", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Model Factory is not defined for \"%s\"'", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "return", "$", "this", "->", "modelFactory", ";", "}" ]
Model Factory getter. @throws Exception If the model factory was not previously set. @return FactoryInterface
[ "Model", "Factory", "getter", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/CollectionContainerTrait.php#L179-L189
train