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
acquia/commerce-manager
modules/acm/src/User/AccessTokenTrait.php
AccessTokenTrait.setAccessToken
public function setAccessToken($token = NULL, $expire = 0) { if (!empty($expire)) { $expire = REQUEST_TIME + $expire; } if (isset(\Drupal::request()->cookies)) { \Drupal::request()->cookies->set('Drupal_visitor_' . $this->accessTokenCookie, $token); } setrawcookie('Drupal.visitor.' . $this->accessTokenCookie, rawurlencode($token), $expire, '/'); }
php
public function setAccessToken($token = NULL, $expire = 0) { if (!empty($expire)) { $expire = REQUEST_TIME + $expire; } if (isset(\Drupal::request()->cookies)) { \Drupal::request()->cookies->set('Drupal_visitor_' . $this->accessTokenCookie, $token); } setrawcookie('Drupal.visitor.' . $this->accessTokenCookie, rawurlencode($token), $expire, '/'); }
[ "public", "function", "setAccessToken", "(", "$", "token", "=", "NULL", ",", "$", "expire", "=", "0", ")", "{", "if", "(", "!", "empty", "(", "$", "expire", ")", ")", "{", "$", "expire", "=", "REQUEST_TIME", "+", "$", "expire", ";", "}", "if", "(...
Sets the customer access token. @param string $token The access token. @param null|int $expire How long from now until the cookie expires, in ms. NULL for expire with session, int for custom expiry.
[ "Sets", "the", "customer", "access", "token", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/User/AccessTokenTrait.php#L45-L55
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php
NestedWidgetContainerTrait.getWidget
public function getWidget() { if ($this->widget === null) { $this->widget = $this->createWidget(); } return $this->widget; }
php
public function getWidget() { if ($this->widget === null) { $this->widget = $this->createWidget(); } return $this->widget; }
[ "public", "function", "getWidget", "(", ")", "{", "if", "(", "$", "this", "->", "widget", "===", "null", ")", "{", "$", "this", "->", "widget", "=", "$", "this", "->", "createWidget", "(", ")", ";", "}", "return", "$", "this", "->", "widget", ";", ...
Retrieve the nested widget. @return WidgetInterface
[ "Retrieve", "the", "nested", "widget", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php#L69-L76
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php
NestedWidgetContainerTrait.widgetData
public function widgetData($key = null, $default = null) { if ($this->widgetData === null) { $this->widgetData = $this->defaultWidgetData(); } if ($key) { if (isset($this->widgetData[$key])) { return $this->widgetData[$key]; } else { if (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } } } return $this->widgetData; }
php
public function widgetData($key = null, $default = null) { if ($this->widgetData === null) { $this->widgetData = $this->defaultWidgetData(); } if ($key) { if (isset($this->widgetData[$key])) { return $this->widgetData[$key]; } else { if (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } } } return $this->widgetData; }
[ "public", "function", "widgetData", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "this", "->", "widgetData", "===", "null", ")", "{", "$", "this", "->", "widgetData", "=", "$", "this", "->", "defaultWidget...
Retrieve the nested widget's options or a single option. @param string|null $key The option key to lookup. @param mixed|null $default The fallback value to return if the $key doesn't exist. @return mixed
[ "Retrieve", "the", "nested", "widget", "s", "options", "or", "a", "single", "option", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php#L184-L203
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php
NestedWidgetContainerTrait.renderDataRecursive
protected function renderDataRecursive($data) { if (!is_array($data) && !($data instanceof Traversable)) { throw new InvalidArgumentException('The renderable data must be iterable.'); } if (!$this->form() instanceof ObjectContainerInterface) { throw new RuntimeException(sprintf( 'The [%s] widget has no data model.', static::CLASS )); } foreach ($data as $key => $val) { if (is_string($val)) { $data[$key] = $this->renderData($val); } elseif (is_array($val) || ($val instanceof Traversable)) { $data[$key] = $this->renderDataRecursive($val); } else { continue; } } return $data; }
php
protected function renderDataRecursive($data) { if (!is_array($data) && !($data instanceof Traversable)) { throw new InvalidArgumentException('The renderable data must be iterable.'); } if (!$this->form() instanceof ObjectContainerInterface) { throw new RuntimeException(sprintf( 'The [%s] widget has no data model.', static::CLASS )); } foreach ($data as $key => $val) { if (is_string($val)) { $data[$key] = $this->renderData($val); } elseif (is_array($val) || ($val instanceof Traversable)) { $data[$key] = $this->renderDataRecursive($val); } else { continue; } } return $data; }
[ "protected", "function", "renderDataRecursive", "(", "$", "data", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", "&&", "!", "(", "$", "data", "instanceof", "Traversable", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The r...
Render the given data recursively. @param array|Traversable $data The data to render. @throws InvalidArgumentException If the data is not iterable. @throws RuntimeException If the form doesn't have a model. @return array|Traversable The rendered data.
[ "Render", "the", "given", "data", "recursively", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php#L256-L280
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php
NestedWidgetContainerTrait.renderData
protected function renderData($data) { $obj = $this->form()->obj(); // Make sure there's an "out" if ($obj instanceof ViewableInterface && $obj->view()) { $data = $obj->view()->render($data, $obj->viewController()); } else { $data = preg_replace_callback('~\{\{\s*(.*?)\s*\}\}~i', [ $this, 'parseDataToken' ], $data); } return $data; }
php
protected function renderData($data) { $obj = $this->form()->obj(); // Make sure there's an "out" if ($obj instanceof ViewableInterface && $obj->view()) { $data = $obj->view()->render($data, $obj->viewController()); } else { $data = preg_replace_callback('~\{\{\s*(.*?)\s*\}\}~i', [ $this, 'parseDataToken' ], $data); } return $data; }
[ "protected", "function", "renderData", "(", "$", "data", ")", "{", "$", "obj", "=", "$", "this", "->", "form", "(", ")", "->", "obj", "(", ")", ";", "// Make sure there's an \"out\"", "if", "(", "$", "obj", "instanceof", "ViewableInterface", "&&", "$", "...
Render the given data. @param string $data The data to render. @return string The rendered data.
[ "Render", "the", "given", "data", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Ui/NestedWidgetContainerTrait.php#L288-L300
train
acquia/commerce-manager
modules/acm_sku/src/ProductInfoHelper.php
ProductInfoHelper.getValue
public function getValue(SKUInterface $sku, string $field_code, string $context, $value) { $event = new ProductInfoRequestedEvent($sku, $field_code, $context, $value); $this->eventDispatcher->dispatch(ProductInfoRequestedEvents::EVENT_NAME, $event); return $event->getValue(); }
php
public function getValue(SKUInterface $sku, string $field_code, string $context, $value) { $event = new ProductInfoRequestedEvent($sku, $field_code, $context, $value); $this->eventDispatcher->dispatch(ProductInfoRequestedEvents::EVENT_NAME, $event); return $event->getValue(); }
[ "public", "function", "getValue", "(", "SKUInterface", "$", "sku", ",", "string", "$", "field_code", ",", "string", "$", "context", ",", "$", "value", ")", "{", "$", "event", "=", "new", "ProductInfoRequestedEvent", "(", "$", "sku", ",", "$", "field_code",...
Dispatch event and get updated value for specific field and context. @param \Drupal\acm_sku\Entity\SKUInterface $sku SKU Entity. @param string $field_code Field code, title/description/etc. @param string $context Context to apply rules plp/pdp/basket. @param mixed $value Default value. @return mixed Processed value.
[ "Dispatch", "event", "and", "get", "updated", "value", "for", "specific", "field", "and", "context", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductInfoHelper.php#L47-L51
train
acquia/commerce-manager
modules/acm_sku/src/ProductInfoHelper.php
ProductInfoHelper.getTitle
public function getTitle(SKUInterface $sku, string $context) { $default = $sku->label(); return $this->getValue($sku, 'title', $context, $default); }
php
public function getTitle(SKUInterface $sku, string $context) { $default = $sku->label(); return $this->getValue($sku, 'title', $context, $default); }
[ "public", "function", "getTitle", "(", "SKUInterface", "$", "sku", ",", "string", "$", "context", ")", "{", "$", "default", "=", "$", "sku", "->", "label", "(", ")", ";", "return", "$", "this", "->", "getValue", "(", "$", "sku", ",", "'title'", ",", ...
Get title for particular SKU. @param \Drupal\acm_sku\Entity\SKUInterface $sku SKU Entity. @param string $context Context to apply rules plp/pdp/basket. @return mixed Processed value.
[ "Get", "title", "for", "particular", "SKU", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/ProductInfoHelper.php#L64-L67
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php
StoredAddressTrait.buildAddressOptions
public function buildAddressOptions() { $address_formatter = new ACMAddressFormatter(); $user = $this->getCurrentCommerceUser(); $addresses = $user->getAddresses(); // Stored addresses. foreach ($addresses as $address) { $option_id = $address['address_id']; $options[$option_id] = [ 'id' => $option_id, 'label' => $address_formatter->render((object) $address), ]; } // New address. $option_id = 'new_address'; $options[$option_id] = [ 'id' => $option_id, 'label' => $this->t('New address'), ]; return $options; }
php
public function buildAddressOptions() { $address_formatter = new ACMAddressFormatter(); $user = $this->getCurrentCommerceUser(); $addresses = $user->getAddresses(); // Stored addresses. foreach ($addresses as $address) { $option_id = $address['address_id']; $options[$option_id] = [ 'id' => $option_id, 'label' => $address_formatter->render((object) $address), ]; } // New address. $option_id = 'new_address'; $options[$option_id] = [ 'id' => $option_id, 'label' => $this->t('New address'), ]; return $options; }
[ "public", "function", "buildAddressOptions", "(", ")", "{", "$", "address_formatter", "=", "new", "ACMAddressFormatter", "(", ")", ";", "$", "user", "=", "$", "this", "->", "getCurrentCommerceUser", "(", ")", ";", "$", "addresses", "=", "$", "user", "->", ...
Builds the address options list. @return array An array of address options.
[ "Builds", "the", "address", "options", "list", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php#L20-L42
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php
StoredAddressTrait.getDefaultAddressOption
protected function getDefaultAddressOption($type, array $options) { $default_option = NULL; // Check if any address is a default for this type. foreach ($options as $option_id => $option) { $key = "default-{$type}"; if (isset($option[$key]) && $option[$key]) { $default_option = $option_id; break; } } // Fallback to the first option. if (!$default_option || !isset($options[$default_option])) { $option_ids = array_keys($options); $default_option = reset($option_ids); } return $default_option; }
php
protected function getDefaultAddressOption($type, array $options) { $default_option = NULL; // Check if any address is a default for this type. foreach ($options as $option_id => $option) { $key = "default-{$type}"; if (isset($option[$key]) && $option[$key]) { $default_option = $option_id; break; } } // Fallback to the first option. if (!$default_option || !isset($options[$default_option])) { $option_ids = array_keys($options); $default_option = reset($option_ids); } return $default_option; }
[ "protected", "function", "getDefaultAddressOption", "(", "$", "type", ",", "array", "$", "options", ")", "{", "$", "default_option", "=", "NULL", ";", "// Check if any address is a default for this type.", "foreach", "(", "$", "options", "as", "$", "option_id", "=>"...
Finds the default address option. @param string $type The address type. @param array $options An array of address options. @return string The key of the default option.
[ "Finds", "the", "default", "address", "option", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php#L55-L74
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php
StoredAddressTrait.findAddress
public static function findAddress($address_id) { $found_address = NULL; $user = \Drupal::service('acm.commerce_user_manager')->getAccount(); $addresses = $user->getAddresses(); $extra_keys = [ 'customer_id', 'customer_address_id', 'region_id', 'default_billing', 'default_shipping', 'extension', ]; foreach ($addresses as $address) { if ($address['address_id'] != $address_id) { continue; } // Found address, strip out extra info. foreach ($extra_keys as $key) { unset($address[$key]); } $found_address = $address; break; } return $found_address; }
php
public static function findAddress($address_id) { $found_address = NULL; $user = \Drupal::service('acm.commerce_user_manager')->getAccount(); $addresses = $user->getAddresses(); $extra_keys = [ 'customer_id', 'customer_address_id', 'region_id', 'default_billing', 'default_shipping', 'extension', ]; foreach ($addresses as $address) { if ($address['address_id'] != $address_id) { continue; } // Found address, strip out extra info. foreach ($extra_keys as $key) { unset($address[$key]); } $found_address = $address; break; } return $found_address; }
[ "public", "static", "function", "findAddress", "(", "$", "address_id", ")", "{", "$", "found_address", "=", "NULL", ";", "$", "user", "=", "\\", "Drupal", "::", "service", "(", "'acm.commerce_user_manager'", ")", "->", "getAccount", "(", ")", ";", "$", "ad...
Finds an address by id. @param string|int $address_id The address id. @return null|array The found address.
[ "Finds", "an", "address", "by", "id", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php#L85-L114
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php
StoredAddressTrait.buildStoredAddressOptions
protected function buildStoredAddressOptions(array $pane_form, FormStateInterface $form_state, $type = 'billing', array $current_address = []) { $field_name = "{$type}_address_options"; $options = $this->buildAddressOptions(); $user_input = $form_state->getUserInput(); $values = NestedArray::getValue($user_input, $pane_form['#parents']); $default_option = NULL; if (!empty($values[$field_name])) { // The form was rebuilt via AJAX, use the submitted value. $default_option = $values[$field_name]; } else { $default_option = $this->getDefaultAddressOption($type, $options); // Check if the saved address matches an option, if so use that as the // default. if ($default_option != 'new_address') { if (isset($current_address['address_id']) && isset($options[$current_address['address_id']])) { $default_option = $current_address['address_id']; } elseif (!empty($current_address)) { $default_option = 'new_address'; } } } // Prepare the form for ajax. $pane_form['#wrapper_id'] = "{$type}-information-wrapper"; $pane_form['#prefix'] = '<div id="' . $pane_form['#wrapper_id'] . '">'; $pane_form['#suffix'] = '</div>'; $pane_form[$field_name] = [ '#type' => 'radios', '#options' => array_column($options, 'label', 'id'), '#default_value' => $default_option, '#ajax' => [ 'callback' => [get_class($this), 'ajaxRefresh'], 'wrapper' => $pane_form['#wrapper_id'], ], '#access' => count($options) > 1, ]; $pane_form['address'] = [ '#type' => 'container', '#attributes' => [ 'id' => ['address_wrapper'], ], '#access' => ($default_option == 'new_address') ? TRUE : FALSE, ]; $checkout_config = \Drupal::config('acm_checkout.settings'); $validate_address = $checkout_config->get("validate_{$type}_address"); $address_review_text = $checkout_config->get("{$type}_address_review_text"); $address_failed_text = $checkout_config->get("{$type}_address_failed_text"); $pane_form['address']['address_fields'] = [ '#type' => 'acm_address', '#default_value' => $current_address, '#display_telephone' => TRUE, '#display_title' => TRUE, '#display_firstname' => TRUE, '#display_lastname' => TRUE, '#validate_address' => $validate_address, '#address_review_text' => $address_review_text, '#address_failed_text' => $address_failed_text, ]; return $pane_form; }
php
protected function buildStoredAddressOptions(array $pane_form, FormStateInterface $form_state, $type = 'billing', array $current_address = []) { $field_name = "{$type}_address_options"; $options = $this->buildAddressOptions(); $user_input = $form_state->getUserInput(); $values = NestedArray::getValue($user_input, $pane_form['#parents']); $default_option = NULL; if (!empty($values[$field_name])) { // The form was rebuilt via AJAX, use the submitted value. $default_option = $values[$field_name]; } else { $default_option = $this->getDefaultAddressOption($type, $options); // Check if the saved address matches an option, if so use that as the // default. if ($default_option != 'new_address') { if (isset($current_address['address_id']) && isset($options[$current_address['address_id']])) { $default_option = $current_address['address_id']; } elseif (!empty($current_address)) { $default_option = 'new_address'; } } } // Prepare the form for ajax. $pane_form['#wrapper_id'] = "{$type}-information-wrapper"; $pane_form['#prefix'] = '<div id="' . $pane_form['#wrapper_id'] . '">'; $pane_form['#suffix'] = '</div>'; $pane_form[$field_name] = [ '#type' => 'radios', '#options' => array_column($options, 'label', 'id'), '#default_value' => $default_option, '#ajax' => [ 'callback' => [get_class($this), 'ajaxRefresh'], 'wrapper' => $pane_form['#wrapper_id'], ], '#access' => count($options) > 1, ]; $pane_form['address'] = [ '#type' => 'container', '#attributes' => [ 'id' => ['address_wrapper'], ], '#access' => ($default_option == 'new_address') ? TRUE : FALSE, ]; $checkout_config = \Drupal::config('acm_checkout.settings'); $validate_address = $checkout_config->get("validate_{$type}_address"); $address_review_text = $checkout_config->get("{$type}_address_review_text"); $address_failed_text = $checkout_config->get("{$type}_address_failed_text"); $pane_form['address']['address_fields'] = [ '#type' => 'acm_address', '#default_value' => $current_address, '#display_telephone' => TRUE, '#display_title' => TRUE, '#display_firstname' => TRUE, '#display_lastname' => TRUE, '#validate_address' => $validate_address, '#address_review_text' => $address_review_text, '#address_failed_text' => $address_failed_text, ]; return $pane_form; }
[ "protected", "function", "buildStoredAddressOptions", "(", "array", "$", "pane_form", ",", "FormStateInterface", "$", "form_state", ",", "$", "type", "=", "'billing'", ",", "array", "$", "current_address", "=", "[", "]", ")", "{", "$", "field_name", "=", "\"{$...
Decorates the form with the stored address options. @param array $pane_form The pane form, containing the following basic properties: - #parents: Identifies the position of the pane form in the overall parent form, and identifies the location where the field values are placed within $form_state->getValues(). @param \Drupal\Core\Form\FormStateInterface $form_state The form state of the parent form. @param string $type Whether it's shipping or billing address. @param array $current_address The current set address. @return array The updated form array.
[ "Decorates", "the", "form", "with", "the", "stored", "address", "options", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/CheckoutPane/StoredAddressTrait.php#L134-L202
train
acquia/commerce-manager
modules/acm_cart/src/Form/CustomerCartForm.php
CustomerCartForm.updateCart
private function updateCart(FormStateInterface $form_state) { try { $cart = $this->cartStorage->updateCart(); $response_message = $cart->get('response_message'); // We will have type of message like error or success. key '0' contains // the response message string while key '1' contains the response // message context/type like success or coupon. if (!empty($response_message[1])) { // If its success. if ($response_message[1] == 'success') { $this->successMessage = $response_message[0]; } elseif ($response_message[1] == 'error_coupon') { // Set the error and require rebuild. $form_state->setErrorByName('coupon', $response_message[0]); $form_state->setRebuild(TRUE); // Remove the coupon and update the cart. $this->cartStorage->setCoupon(''); $this->updateCart($form_state); } } } catch (\Exception $e) { if (acm_is_exception_api_down_exception($e)) { $this->messenger()->addError($e->getMessage()); $form_state->setErrorByName('custom', $e->getMessage()); $form_state->setRebuild(TRUE); } // Dispatch event so action can be taken. $dispatcher = \Drupal::service('event_dispatcher'); $event = new UpdateCartErrorEvent($e); $dispatcher->dispatch(UpdateCartErrorEvent::SUBMIT, $event); $this->messenger()->addError($e->getMessage()); } }
php
private function updateCart(FormStateInterface $form_state) { try { $cart = $this->cartStorage->updateCart(); $response_message = $cart->get('response_message'); // We will have type of message like error or success. key '0' contains // the response message string while key '1' contains the response // message context/type like success or coupon. if (!empty($response_message[1])) { // If its success. if ($response_message[1] == 'success') { $this->successMessage = $response_message[0]; } elseif ($response_message[1] == 'error_coupon') { // Set the error and require rebuild. $form_state->setErrorByName('coupon', $response_message[0]); $form_state->setRebuild(TRUE); // Remove the coupon and update the cart. $this->cartStorage->setCoupon(''); $this->updateCart($form_state); } } } catch (\Exception $e) { if (acm_is_exception_api_down_exception($e)) { $this->messenger()->addError($e->getMessage()); $form_state->setErrorByName('custom', $e->getMessage()); $form_state->setRebuild(TRUE); } // Dispatch event so action can be taken. $dispatcher = \Drupal::service('event_dispatcher'); $event = new UpdateCartErrorEvent($e); $dispatcher->dispatch(UpdateCartErrorEvent::SUBMIT, $event); $this->messenger()->addError($e->getMessage()); } }
[ "private", "function", "updateCart", "(", "FormStateInterface", "$", "form_state", ")", "{", "try", "{", "$", "cart", "=", "$", "this", "->", "cartStorage", "->", "updateCart", "(", ")", ";", "$", "response_message", "=", "$", "cart", "->", "get", "(", "...
Cart update utility. @param \Drupal\Core\Form\FormStateInterface $form_state FormStateInterface object.
[ "Cart", "update", "utility", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/Form/CustomerCartForm.php#L273-L309
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.setData
public function setData(array $data) { $keys = $this->validDataFromRequest(); $data = array_intersect_key($data, array_flip($keys)); $this->mergeData($data); return $this; }
php
public function setData(array $data) { $keys = $this->validDataFromRequest(); $data = array_intersect_key($data, array_flip($keys)); $this->mergeData($data); return $this; }
[ "public", "function", "setData", "(", "array", "$", "data", ")", "{", "$", "keys", "=", "$", "this", "->", "validDataFromRequest", "(", ")", ";", "$", "data", "=", "array_intersect_key", "(", "$", "data", ",", "array_flip", "(", "$", "keys", ")", ")", ...
Sets the action data. @param array $data The action data. @return self
[ "Sets", "the", "action", "data", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L94-L101
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.getParams
public function getParams(array $keys = null) { $params = $this->params; if ($keys) { $subset = []; foreach ($keys as $key) { if (array_key_exists($key, $params)) { $subset[$key] = $params[$key]; } } return $subset; } return $params; }
php
public function getParams(array $keys = null) { $params = $this->params; if ($keys) { $subset = []; foreach ($keys as $key) { if (array_key_exists($key, $params)) { $subset[$key] = $params[$key]; } } return $subset; } return $params; }
[ "public", "function", "getParams", "(", "array", "$", "keys", "=", "null", ")", "{", "$", "params", "=", "$", "this", "->", "params", ";", "if", "(", "$", "keys", ")", "{", "$", "subset", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "...
Get the associative array of request parameters. @param array|null $keys Subset of keys to retrieve. @return array|null
[ "Get", "the", "associative", "array", "of", "request", "parameters", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L147-L162
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.getParam
public function getParam($key, $default = null) { $params = $this->params; if (is_array($params) && isset($params[$key])) { $result = $params[$key]; } else { if (!is_string($default) && is_callable($default)) { $result = $default(); } else { $result = $default; } } return $result; }
php
public function getParam($key, $default = null) { $params = $this->params; if (is_array($params) && isset($params[$key])) { $result = $params[$key]; } else { if (!is_string($default) && is_callable($default)) { $result = $default(); } else { $result = $default; } } return $result; }
[ "public", "function", "getParam", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "$", "params", "=", "$", "this", "->", "params", ";", "if", "(", "is_array", "(", "$", "params", ")", "&&", "isset", "(", "$", "params", "[", "$", "key...
Get the request parameter value. @param string $key The parameter key. @param string $default The default value. @return mixed The parameter value.
[ "Get", "the", "request", "parameter", "value", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L171-L185
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.assertValidDisk
protected function assertValidDisk($disk) { $translator = $this->translator(); if ($disk === null) { $message = $translator->translate( 'Default filesystem [{{ defaultFilesystemConnection }}] is not defined', [ '{{ defaultFilesystemConnection }}' => 'config.filesystem.default_connection' ] ); throw new InvalidArgumentException($message, 400); } if (!is_string($disk)) { $actualType = is_object($disk) ? get_class($disk) : gettype($disk); $message = $translator->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"disk"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } if (!isset($this->filesystems[$disk])) { $message = $translator->translate('Filesystem identifier "{{ fsIdent }}" is not defined.', [ '{{ fsIdent }}' => $disk ]); throw new InvalidArgumentException($message, 400); } }
php
protected function assertValidDisk($disk) { $translator = $this->translator(); if ($disk === null) { $message = $translator->translate( 'Default filesystem [{{ defaultFilesystemConnection }}] is not defined', [ '{{ defaultFilesystemConnection }}' => 'config.filesystem.default_connection' ] ); throw new InvalidArgumentException($message, 400); } if (!is_string($disk)) { $actualType = is_object($disk) ? get_class($disk) : gettype($disk); $message = $translator->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"disk"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } if (!isset($this->filesystems[$disk])) { $message = $translator->translate('Filesystem identifier "{{ fsIdent }}" is not defined.', [ '{{ fsIdent }}' => $disk ]); throw new InvalidArgumentException($message, 400); } }
[ "protected", "function", "assertValidDisk", "(", "$", "disk", ")", "{", "$", "translator", "=", "$", "this", "->", "translator", "(", ")", ";", "if", "(", "$", "disk", "===", "null", ")", "{", "$", "message", "=", "$", "translator", "->", "translate", ...
Asserts that the filesystem connection is valid, throws an exception if not. @param mixed $disk A filesystem connection identifier. @throws InvalidArgumentException If the filesystem is not a string or NULL. @return void
[ "Asserts", "that", "the", "filesystem", "connection", "is", "valid", "throws", "an", "exception", "if", "not", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L334-L370
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.assertValidPath
protected function assertValidPath($path) { $translator = $this->translator(); if (empty($path) && !is_numeric($path)) { $message = $translator->translate( '{{ parameter }} required and must be a {{ expectedType }}', [ '{{ parameter }}' => '"path"', '{{ expectedType }}' => 'string', ] ); throw new InvalidArgumentException($message, 400); } elseif (!is_string($path)) { $actualType = is_object($path) ? get_class($path) : gettype($path); $message = $translator->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"path"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } }
php
protected function assertValidPath($path) { $translator = $this->translator(); if (empty($path) && !is_numeric($path)) { $message = $translator->translate( '{{ parameter }} required and must be a {{ expectedType }}', [ '{{ parameter }}' => '"path"', '{{ expectedType }}' => 'string', ] ); throw new InvalidArgumentException($message, 400); } elseif (!is_string($path)) { $actualType = is_object($path) ? get_class($path) : gettype($path); $message = $translator->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"path"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } }
[ "protected", "function", "assertValidPath", "(", "$", "path", ")", "{", "$", "translator", "=", "$", "this", "->", "translator", "(", ")", ";", "if", "(", "empty", "(", "$", "path", ")", "&&", "!", "is_numeric", "(", "$", "path", ")", ")", "{", "$"...
Asserts that the path is valid, throws an exception if not. @param mixed $path A file path. @throws InvalidArgumentException If the path is not a string. @return void
[ "Asserts", "that", "the", "path", "is", "valid", "throws", "an", "exception", "if", "not", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L379-L406
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.assertValidName
protected function assertValidName($name) { if (!is_string($name) && $name !== null) { $actualType = is_object($name) ? get_class($name) : gettype($name); $message = $this->translator()->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"name"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } }
php
protected function assertValidName($name) { if (!is_string($name) && $name !== null) { $actualType = is_object($name) ? get_class($name) : gettype($name); $message = $this->translator()->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"name"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } }
[ "protected", "function", "assertValidName", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", "&&", "$", "name", "!==", "null", ")", "{", "$", "actualType", "=", "is_object", "(", "$", "name", ")", "?", "get_class", "(",...
Asserts that the custom file name is valid, throws an exception if not. @param mixed $name A custom file name. @throws InvalidArgumentException If the name is not a string or NULL. @return void
[ "Asserts", "that", "the", "custom", "file", "name", "is", "valid", "throws", "an", "exception", "if", "not", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L415-L430
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Filesystem/LoadAction.php
LoadAction.assertValidDisposition
protected function assertValidDisposition($disposition) { $translator = $this->translator(); if (!in_array($disposition, [ self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE ])) { throw new InvalidArgumentException(sprintf( 'The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE )); } if (!is_string($disposition) && $disposition !== null) { $actualType = is_object($disposition) ? get_class($disposition) : gettype($disposition); $message = $translator->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"disposition"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } }
php
protected function assertValidDisposition($disposition) { $translator = $this->translator(); if (!in_array($disposition, [ self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE ])) { throw new InvalidArgumentException(sprintf( 'The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE )); } if (!is_string($disposition) && $disposition !== null) { $actualType = is_object($disposition) ? get_class($disposition) : gettype($disposition); $message = $translator->translate( '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}', [ '{{ parameter }}' => '"disposition"', '{{ expectedType }}' => 'string', '{{ actualType }}' => $actualType, ] ); throw new InvalidArgumentException($message, 400); } }
[ "protected", "function", "assertValidDisposition", "(", "$", "disposition", ")", "{", "$", "translator", "=", "$", "this", "->", "translator", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "disposition", ",", "[", "self", "::", "DISPOSITION_ATTACHMENT...
Asserts that the response disposition is valid, throws an exception if not. @param mixed $disposition A response disposition. @throws InvalidArgumentException If the disposition is not a string or NULL. @return void
[ "Asserts", "that", "the", "response", "disposition", "is", "valid", "throws", "an", "exception", "if", "not", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Filesystem/LoadAction.php#L439-L464
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/MapWidgetInput.php
MapWidgetInput.setMapOptions
public function setMapOptions(array $settings) { if (isset($settings['api_key'])) { $this->setApiKey($settings['api_key']); } if ($this->mapOptions) { $this->mapOptions = array_replace_recursive($this->mapOptions, $settings); } else { $this->mapOptions = array_replace_recursive($this->defaultMapOptions(), $settings); } return $this; }
php
public function setMapOptions(array $settings) { if (isset($settings['api_key'])) { $this->setApiKey($settings['api_key']); } if ($this->mapOptions) { $this->mapOptions = array_replace_recursive($this->mapOptions, $settings); } else { $this->mapOptions = array_replace_recursive($this->defaultMapOptions(), $settings); } return $this; }
[ "public", "function", "setMapOptions", "(", "array", "$", "settings", ")", "{", "if", "(", "isset", "(", "$", "settings", "[", "'api_key'", "]", ")", ")", "{", "$", "this", "->", "setApiKey", "(", "$", "settings", "[", "'api_key'", "]", ")", ";", "}"...
Set the map widget's options. This method always merges default settings. @param array $settings The map widget options. @return MapWidgetInput Chainable
[ "Set", "the", "map", "widget", "s", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/MapWidgetInput.php#L63-L76
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/MapWidgetInput.php
MapWidgetInput.mapOptions
public function mapOptions() { if ($this->mapOptions === null) { $this->mapOptions = $this->defaultMapOptions(); } return $this->mapOptions; }
php
public function mapOptions() { if ($this->mapOptions === null) { $this->mapOptions = $this->defaultMapOptions(); } return $this->mapOptions; }
[ "public", "function", "mapOptions", "(", ")", "{", "if", "(", "$", "this", "->", "mapOptions", "===", "null", ")", "{", "$", "this", "->", "mapOptions", "=", "$", "this", "->", "defaultMapOptions", "(", ")", ";", "}", "return", "$", "this", "->", "ma...
Retrieve the map widget's options. @return array
[ "Retrieve", "the", "map", "widget", "s", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/MapWidgetInput.php#L130-L136
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminScript.php
AdminScript.booleanInput
private function booleanInput(PropertyInterface $prop, $label) { $climate = $this->climate(); $opts = [ 1 => $prop->trueLabel(), 0 => $prop->falseLabel() ]; $input = $climate->radio( $label, $opts ); return $input; }
php
private function booleanInput(PropertyInterface $prop, $label) { $climate = $this->climate(); $opts = [ 1 => $prop->trueLabel(), 0 => $prop->falseLabel() ]; $input = $climate->radio( $label, $opts ); return $input; }
[ "private", "function", "booleanInput", "(", "PropertyInterface", "$", "prop", ",", "$", "label", ")", "{", "$", "climate", "=", "$", "this", "->", "climate", "(", ")", ";", "$", "opts", "=", "[", "1", "=>", "$", "prop", "->", "trueLabel", "(", ")", ...
Get a CLI input from a boolean property. @param PropertyInterface $prop The property to retrieve input from. @param string $label The input label. @return LeagueInput The League's terminal input object.
[ "Get", "a", "CLI", "input", "from", "a", "boolean", "property", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminScript.php#L96-L109
train
acquia/commerce-manager
modules/acm_checkout/src/Controller/CheckoutController.php
CheckoutController.checkAccess
public function checkAccess(AccountInterface $account) { $cart = $this->cartStorage; if (empty($cart) || $cart->isEmpty()) { return AccessResult::forbidden('Invalid cart'); } return AccessResult::allowedIfHasPermission($account, 'access checkout'); }
php
public function checkAccess(AccountInterface $account) { $cart = $this->cartStorage; if (empty($cart) || $cart->isEmpty()) { return AccessResult::forbidden('Invalid cart'); } return AccessResult::allowedIfHasPermission($account, 'access checkout'); }
[ "public", "function", "checkAccess", "(", "AccountInterface", "$", "account", ")", "{", "$", "cart", "=", "$", "this", "->", "cartStorage", ";", "if", "(", "empty", "(", "$", "cart", ")", "||", "$", "cart", "->", "isEmpty", "(", ")", ")", "{", "retur...
Checks access for the form page. @param \Drupal\Core\Session\AccountInterface $account The current user account. @return \Drupal\Core\Access\AccessResult The access result.
[ "Checks", "access", "for", "the", "form", "page", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Controller/CheckoutController.php#L209-L217
train
acquia/commerce-manager
modules/acm_checkout/src/Controller/CheckoutController.php
CheckoutController.loadCheckoutFlowPlugin
protected function loadCheckoutFlowPlugin() { $checkoutFlowPlugin = $this->config->get('checkout_flow_plugin') ?: 'multistep_default'; return $this->acmCheckoutFlowManager->createInstance($checkoutFlowPlugin, ['validate_current_step' => TRUE]); }
php
protected function loadCheckoutFlowPlugin() { $checkoutFlowPlugin = $this->config->get('checkout_flow_plugin') ?: 'multistep_default'; return $this->acmCheckoutFlowManager->createInstance($checkoutFlowPlugin, ['validate_current_step' => TRUE]); }
[ "protected", "function", "loadCheckoutFlowPlugin", "(", ")", "{", "$", "checkoutFlowPlugin", "=", "$", "this", "->", "config", "->", "get", "(", "'checkout_flow_plugin'", ")", "?", ":", "'multistep_default'", ";", "return", "$", "this", "->", "acmCheckoutFlowManag...
Loads the configured CheckoutFlow plugin. @return object An instance of the CheckoutFlow plugin.
[ "Loads", "the", "configured", "CheckoutFlow", "plugin", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Controller/CheckoutController.php#L225-L228
train
acquia/commerce-manager
modules/acm_sku/src/Plugin/rest/resource/ProductSyncResource.php
ProductSyncResource.errorHandler
public function errorHandler(int $error_number, string $error_message) { switch ($error_number) { case E_RECOVERABLE_ERROR: throw new Exception($error_message, $error_number); } }
php
public function errorHandler(int $error_number, string $error_message) { switch ($error_number) { case E_RECOVERABLE_ERROR: throw new Exception($error_message, $error_number); } }
[ "public", "function", "errorHandler", "(", "int", "$", "error_number", ",", "string", "$", "error_message", ")", "{", "switch", "(", "$", "error_number", ")", "{", "case", "E_RECOVERABLE_ERROR", ":", "throw", "new", "Exception", "(", "$", "error_message", ",",...
Custom error handler that converts E_RECOVERABLE_ERROR into an exception. @param int $error_number The error number. @param string $error_message The error message. @throws \Exception
[ "Custom", "error", "handler", "that", "converts", "E_RECOVERABLE_ERROR", "into", "an", "exception", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Plugin/rest/resource/ProductSyncResource.php#L134-L139
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Script/Translation/TranslateScript.php
TranslateScript.oppositeLanguages
public function oppositeLanguages() { $cfg = $this->app()->config(); $locales = $this->locales(); $languages = $locales['languages']; $opposite = []; $orig = $this->origLanguage(); foreach ($languages as $ident => $opts) { if ($ident != $orig) { $opposite[] = $ident; } } return $opposite; }
php
public function oppositeLanguages() { $cfg = $this->app()->config(); $locales = $this->locales(); $languages = $locales['languages']; $opposite = []; $orig = $this->origLanguage(); foreach ($languages as $ident => $opts) { if ($ident != $orig) { $opposite[] = $ident; } } return $opposite; }
[ "public", "function", "oppositeLanguages", "(", ")", "{", "$", "cfg", "=", "$", "this", "->", "app", "(", ")", "->", "config", "(", ")", ";", "$", "locales", "=", "$", "this", "->", "locales", "(", ")", ";", "$", "languages", "=", "$", "locales", ...
Get opposite languages from DATABASE @return [type] [description]
[ "Get", "opposite", "languages", "from", "DATABASE" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Script/Translation/TranslateScript.php#L353-L368
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Script/Translation/TranslateScript.php
TranslateScript.locales
public function locales() { if ($this->locales) { return $this->locales; } $cfg = $this->app()->config(); $locales = isset($cfg['locales']) ? $cfg['locales'] : []; $languages = isset($locales['languages']) ? $locales['languages'] : []; $file = isset($locales['file']) ? $locales['file'] : $this->argOrInput('output'); // Default to FR $default = isset($locales['default_language']) ? $locales['default_language'] : 'fr'; $this->locales = [ 'languages' => $languages, 'file' => $file, 'default_language' => $default ]; return $this->locales; }
php
public function locales() { if ($this->locales) { return $this->locales; } $cfg = $this->app()->config(); $locales = isset($cfg['locales']) ? $cfg['locales'] : []; $languages = isset($locales['languages']) ? $locales['languages'] : []; $file = isset($locales['file']) ? $locales['file'] : $this->argOrInput('output'); // Default to FR $default = isset($locales['default_language']) ? $locales['default_language'] : 'fr'; $this->locales = [ 'languages' => $languages, 'file' => $file, 'default_language' => $default ]; return $this->locales; }
[ "public", "function", "locales", "(", ")", "{", "if", "(", "$", "this", "->", "locales", ")", "{", "return", "$", "this", "->", "locales", ";", "}", "$", "cfg", "=", "$", "this", "->", "app", "(", ")", "->", "config", "(", ")", ";", "$", "local...
Locales set in config.json Expects languages | file | default_language @return array
[ "Locales", "set", "in", "config", ".", "json", "Expects", "languages", "|", "file", "|", "default_language" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Script/Translation/TranslateScript.php#L376-L395
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Script/Translation/TranslateScript.php
TranslateScript.columns
public function columns() { $orig = $this->origLanguage(); $opposites = $this->oppositeLanguages(); $columns = [ $orig ]; foreach ($opposites as $lang) { $columns[] = $lang; } // Add context. $columns[] = 'context'; return $columns; }
php
public function columns() { $orig = $this->origLanguage(); $opposites = $this->oppositeLanguages(); $columns = [ $orig ]; foreach ($opposites as $lang) { $columns[] = $lang; } // Add context. $columns[] = 'context'; return $columns; }
[ "public", "function", "columns", "(", ")", "{", "$", "orig", "=", "$", "this", "->", "origLanguage", "(", ")", ";", "$", "opposites", "=", "$", "this", "->", "oppositeLanguages", "(", ")", ";", "$", "columns", "=", "[", "$", "orig", "]", ";", "fore...
Columns of CSV file This is already built to take multiple languages @return array
[ "Columns", "of", "CSV", "file", "This", "is", "already", "built", "to", "take", "multiple", "languages" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Script/Translation/TranslateScript.php#L403-L418
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Service/Exporter.php
Exporter.export
public function export() { $headers = $this->fileHeaders(); $rows = $this->rows(); $writer = Writer::createFromFileObject(new SplTempFileObject()); $writer->setNewline("\r\n"); $writer->setOutputBOM(Writer::BOM_UTF8); $writer->insertOne($headers); foreach ($rows as $r) { $writer->insertOne($r); } $writer->output($this->filename()); }
php
public function export() { $headers = $this->fileHeaders(); $rows = $this->rows(); $writer = Writer::createFromFileObject(new SplTempFileObject()); $writer->setNewline("\r\n"); $writer->setOutputBOM(Writer::BOM_UTF8); $writer->insertOne($headers); foreach ($rows as $r) { $writer->insertOne($r); } $writer->output($this->filename()); }
[ "public", "function", "export", "(", ")", "{", "$", "headers", "=", "$", "this", "->", "fileHeaders", "(", ")", ";", "$", "rows", "=", "$", "this", "->", "rows", "(", ")", ";", "$", "writer", "=", "Writer", "::", "createFromFileObject", "(", "new", ...
Export to CSV @return void
[ "Export", "to", "CSV" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Service/Exporter.php#L149-L164
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Service/Exporter.php
Exporter.collection
public function collection() { if ($this->collection) { return $this->collection; } if (!$this->collectionConfig()) { throw new Exception(sprintf( 'Collection Config required for "%s"', get_class($this) )); } $collection = new CollectionLoader([ 'logger' => $this->logger, 'factory' => $this->modelFactory() ]); $collection->setModel($this->proto()); $collection->setData($this->collectionConfig()); $this->collection = $collection->load(); return $this->collection; }
php
public function collection() { if ($this->collection) { return $this->collection; } if (!$this->collectionConfig()) { throw new Exception(sprintf( 'Collection Config required for "%s"', get_class($this) )); } $collection = new CollectionLoader([ 'logger' => $this->logger, 'factory' => $this->modelFactory() ]); $collection->setModel($this->proto()); $collection->setData($this->collectionConfig()); $this->collection = $collection->load(); return $this->collection; }
[ "public", "function", "collection", "(", ")", "{", "if", "(", "$", "this", "->", "collection", ")", "{", "return", "$", "this", "->", "collection", ";", "}", "if", "(", "!", "$", "this", "->", "collectionConfig", "(", ")", ")", "{", "throw", "new", ...
Actual object collection @throws Exception If collection config is not set. @return Collection Collection from the export config.
[ "Actual", "object", "collection" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Service/Exporter.php#L171-L195
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Service/Exporter.php
Exporter.prepareOptions
private function prepareOptions() { $metadata = $this->metadata(); // Can be override from the outside. if (!$this->exportIdent()) { $exportIdent = $this->exportIdent() ? : $this->metadata()->get('admin.default_export'); if (!$exportIdent) { throw new Exception(sprintf( 'No export ident defined for "%s" in %s', $this->objType(), get_class($this) )); } $this->setExportIdent($exportIdent); } $export = $metadata->get('admin.export.'.$this->exportIdent()); if (!$export) { throw new Exception(sprintf( 'No export data defined for "%s" at "%s" in %s', $this->objType(), $this->exportIdent(), get_class($this) )); } if (is_string($export)) { $export = $metadata->get('admin.lists.'.$export); if (!$export) { throw new Exception(sprintf( 'No export data defined for "%s" in %s', $this->objType(), get_class($this) )); } } if (!isset($export['properties'])) { throw new Exception(sprintf( 'No properties defined to export "%s" in %s', $this->objType(), get_class($this) )); } if (isset($export['exporter_options'])) { $opts = $export['exporter_options']; if (isset($opts['convert_br_to_newlines'])) { $this->setConvertBrToNewlines($opts['convert_br_to_newlines']); } if (isset($opts['strip_tags'])) { $this->setStripTags($opts['strip_tags']); } if (isset($opts['filename'])) { $this->setFilename($opts['filename']); } } // Default filename. // Filename is not a requirement if (!$this->filename()) { $ts = new DateTime('now'); $filename = str_replace('/', '.', strtolower($this->objType())).'-export-'.$ts->format('Ymd.His').'.csv'; $this->setFilename($filename); } // Properties to be exported // They will defined the file header and the rows. $this->setProperties($export['properties']); // Unnecessary for collection config. unset($export['properties']); unset($export['exporter_options']); // The rest is just collection config $this->setCollectionConfig($export); return $this; }
php
private function prepareOptions() { $metadata = $this->metadata(); // Can be override from the outside. if (!$this->exportIdent()) { $exportIdent = $this->exportIdent() ? : $this->metadata()->get('admin.default_export'); if (!$exportIdent) { throw new Exception(sprintf( 'No export ident defined for "%s" in %s', $this->objType(), get_class($this) )); } $this->setExportIdent($exportIdent); } $export = $metadata->get('admin.export.'.$this->exportIdent()); if (!$export) { throw new Exception(sprintf( 'No export data defined for "%s" at "%s" in %s', $this->objType(), $this->exportIdent(), get_class($this) )); } if (is_string($export)) { $export = $metadata->get('admin.lists.'.$export); if (!$export) { throw new Exception(sprintf( 'No export data defined for "%s" in %s', $this->objType(), get_class($this) )); } } if (!isset($export['properties'])) { throw new Exception(sprintf( 'No properties defined to export "%s" in %s', $this->objType(), get_class($this) )); } if (isset($export['exporter_options'])) { $opts = $export['exporter_options']; if (isset($opts['convert_br_to_newlines'])) { $this->setConvertBrToNewlines($opts['convert_br_to_newlines']); } if (isset($opts['strip_tags'])) { $this->setStripTags($opts['strip_tags']); } if (isset($opts['filename'])) { $this->setFilename($opts['filename']); } } // Default filename. // Filename is not a requirement if (!$this->filename()) { $ts = new DateTime('now'); $filename = str_replace('/', '.', strtolower($this->objType())).'-export-'.$ts->format('Ymd.His').'.csv'; $this->setFilename($filename); } // Properties to be exported // They will defined the file header and the rows. $this->setProperties($export['properties']); // Unnecessary for collection config. unset($export['properties']); unset($export['exporter_options']); // The rest is just collection config $this->setCollectionConfig($export); return $this; }
[ "private", "function", "prepareOptions", "(", ")", "{", "$", "metadata", "=", "$", "this", "->", "metadata", "(", ")", ";", "// Can be override from the outside.", "if", "(", "!", "$", "this", "->", "exportIdent", "(", ")", ")", "{", "$", "exportIdent", "=...
Set all data from the metadata. @throws Exception If no export ident is specified or found. @throws Exception If no export data is found. @throws Exception If no properties are defined. @return Exporter Chainable.
[ "Set", "all", "data", "from", "the", "metadata", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Service/Exporter.php#L235-L315
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Service/Exporter.php
Exporter.rows
private function rows() { $collection = $this->collection(); $properties = $this->properties(); $metadata = $this->metadata(); foreach ($collection as $c) { $row = []; foreach ($properties as $p) { // Use the property factory to get // the proper val to output in csv // as a string. $propertyMetadata = $metadata->get('properties.'.$p); $prop = $this->propertyFactory()->create($propertyMetadata['type']); $prop->setIdent($p); $prop->setData($propertyMetadata); $row[] = $this->stripContent($prop->displayVal($c->propertyValue($p))); } yield $row; } }
php
private function rows() { $collection = $this->collection(); $properties = $this->properties(); $metadata = $this->metadata(); foreach ($collection as $c) { $row = []; foreach ($properties as $p) { // Use the property factory to get // the proper val to output in csv // as a string. $propertyMetadata = $metadata->get('properties.'.$p); $prop = $this->propertyFactory()->create($propertyMetadata['type']); $prop->setIdent($p); $prop->setData($propertyMetadata); $row[] = $this->stripContent($prop->displayVal($c->propertyValue($p))); } yield $row; } }
[ "private", "function", "rows", "(", ")", "{", "$", "collection", "=", "$", "this", "->", "collection", "(", ")", ";", "$", "properties", "=", "$", "this", "->", "properties", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "metadata", "(", ...
CSV rows from collection @return array Rows with data from collection.
[ "CSV", "rows", "from", "collection" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Service/Exporter.php#L348-L368
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Service/Exporter.php
Exporter.stripContent
private function stripContent($text) { if ($this->convertBrToNewlines()) { $text = $this->brToNewline($text); } if ($this->stripTags()) { $text = strip_tags($text); } return $text; }
php
private function stripContent($text) { if ($this->convertBrToNewlines()) { $text = $this->brToNewline($text); } if ($this->stripTags()) { $text = strip_tags($text); } return $text; }
[ "private", "function", "stripContent", "(", "$", "text", ")", "{", "if", "(", "$", "this", "->", "convertBrToNewlines", "(", ")", ")", "{", "$", "text", "=", "$", "this", "->", "brToNewline", "(", "$", "text", ")", ";", "}", "if", "(", "$", "this",...
Clean output content. @param string $text Text to be stripped. @return string Stripped text.
[ "Clean", "output", "content", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Service/Exporter.php#L574-L583
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/BaseUrlTrait.php
BaseUrlTrait.baseUrl
public function baseUrl($targetPath = null) { if (!isset($this->baseUrl)) { throw new RuntimeException(sprintf( 'The base URI is not defined for [%s]', get_class($this) )); } if ($targetPath !== null) { return $this->createAbsoluteUrl($this->baseUrl, $targetPath); } return rtrim($this->baseUrl, '/').'/'; }
php
public function baseUrl($targetPath = null) { if (!isset($this->baseUrl)) { throw new RuntimeException(sprintf( 'The base URI is not defined for [%s]', get_class($this) )); } if ($targetPath !== null) { return $this->createAbsoluteUrl($this->baseUrl, $targetPath); } return rtrim($this->baseUrl, '/').'/'; }
[ "public", "function", "baseUrl", "(", "$", "targetPath", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "baseUrl", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'The base URI is not defined for [%s]'", ",",...
Retrieve the base URI of the application. @param mixed $targetPath Optional target path. @throws RuntimeException If the base URI is missing. @return string|null
[ "Retrieve", "the", "base", "URI", "of", "the", "application", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/BaseUrlTrait.php#L49-L63
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/BaseUrlTrait.php
BaseUrlTrait.adminUrl
public function adminUrl($targetPath = null) { if (!isset($this->adminUrl)) { throw new RuntimeException(sprintf( 'The Admin URI is not defined for [%s]', get_class($this) )); } if ($targetPath !== null) { return $this->createAbsoluteUrl($this->adminUrl, $targetPath); } return rtrim($this->adminUrl, '/').'/'; }
php
public function adminUrl($targetPath = null) { if (!isset($this->adminUrl)) { throw new RuntimeException(sprintf( 'The Admin URI is not defined for [%s]', get_class($this) )); } if ($targetPath !== null) { return $this->createAbsoluteUrl($this->adminUrl, $targetPath); } return rtrim($this->adminUrl, '/').'/'; }
[ "public", "function", "adminUrl", "(", "$", "targetPath", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "adminUrl", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'The Admin URI is not defined for [%s]'", "...
Retrieve the URI of the administration-area. @param mixed $targetPath Optional target path. @throws RuntimeException If the admin URI is missing. @return UriInterface|null
[ "Retrieve", "the", "URI", "of", "the", "administration", "-", "area", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/BaseUrlTrait.php#L85-L99
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/BaseUrlTrait.php
BaseUrlTrait.isRelativeUri
protected function isRelativeUri($uri) { if ($uri && !parse_url($uri, PHP_URL_SCHEME)) { if (!in_array($uri[0], [ '/', '#', '?' ])) { return true; } } return false; }
php
protected function isRelativeUri($uri) { if ($uri && !parse_url($uri, PHP_URL_SCHEME)) { if (!in_array($uri[0], [ '/', '#', '?' ])) { return true; } } return false; }
[ "protected", "function", "isRelativeUri", "(", "$", "uri", ")", "{", "if", "(", "$", "uri", "&&", "!", "parse_url", "(", "$", "uri", ",", "PHP_URL_SCHEME", ")", ")", "{", "if", "(", "!", "in_array", "(", "$", "uri", "[", "0", "]", ",", "[", "'/'"...
Determine if the given URI is relative. @param string $uri A URI path to test. @return boolean
[ "Determine", "if", "the", "given", "URI", "is", "relative", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/BaseUrlTrait.php#L107-L116
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/PaginationWidget.php
PaginationWidget.pager
protected function pager() { if ($this->pager === null) { $this->pager = $this->createPagination(); } return $this->pager; }
php
protected function pager() { if ($this->pager === null) { $this->pager = $this->createPagination(); } return $this->pager; }
[ "protected", "function", "pager", "(", ")", "{", "if", "(", "$", "this", "->", "pager", "===", "null", ")", "{", "$", "this", "->", "pager", "=", "$", "this", "->", "createPagination", "(", ")", ";", "}", "return", "$", "this", "->", "pager", ";", ...
Retrieve the Paginationb object. @return PaginationInterface
[ "Retrieve", "the", "Paginationb", "object", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/PaginationWidget.php#L48-L55
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Script/User/CreateScript.php
CreateScript.createUser
private function createUser() { $this->climate()->underline()->out( $this->translator()->translate('Create a new Charcoal Administrator User') ); $user = $this->modelFactory()->create(User::class); $prompts = $this->userPrompts(); $properties = $user->properties(array_keys($prompts)); $vals = []; foreach ($properties as $prop) { if (!in_array($prop->ident(), array_keys($prompts))) { continue; } $prompt = $prompts[$prop->ident()]; if ($prompt['property']) { $v = $prompt['property']; } else { $v = $this->promptProperty($prop, $prompt['label']); } if (isset($prompt['validation'])) { call_user_func($prompt['validation'], $v); } $prop->setVal($v); $vals[$prop->ident()] = $v; } // Trigger reset password $user->resetPassword($vals['password']); unset($vals['password']); $user->setFlatData($vals); $ret = $user->save(); if ($ret) { $this->climate()->green()->out("\n".sprintf('Success! User "%s" created.', $user->email())); } else { $this->climate()->red()->out("\nError. User could not be created."); } }
php
private function createUser() { $this->climate()->underline()->out( $this->translator()->translate('Create a new Charcoal Administrator User') ); $user = $this->modelFactory()->create(User::class); $prompts = $this->userPrompts(); $properties = $user->properties(array_keys($prompts)); $vals = []; foreach ($properties as $prop) { if (!in_array($prop->ident(), array_keys($prompts))) { continue; } $prompt = $prompts[$prop->ident()]; if ($prompt['property']) { $v = $prompt['property']; } else { $v = $this->promptProperty($prop, $prompt['label']); } if (isset($prompt['validation'])) { call_user_func($prompt['validation'], $v); } $prop->setVal($v); $vals[$prop->ident()] = $v; } // Trigger reset password $user->resetPassword($vals['password']); unset($vals['password']); $user->setFlatData($vals); $ret = $user->save(); if ($ret) { $this->climate()->green()->out("\n".sprintf('Success! User "%s" created.', $user->email())); } else { $this->climate()->red()->out("\nError. User could not be created."); } }
[ "private", "function", "createUser", "(", ")", "{", "$", "this", "->", "climate", "(", ")", "->", "underline", "(", ")", "->", "out", "(", "$", "this", "->", "translator", "(", ")", "->", "translate", "(", "'Create a new Charcoal Administrator User'", ")", ...
Create a new user in the database @return void
[ "Create", "a", "new", "user", "in", "the", "database" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Script/User/CreateScript.php#L94-L137
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminWidget.php
AdminWidget.dataSourceFilter
public function dataSourceFilter($sourceIdent) { if (!is_string($sourceIdent)) { throw new InvalidArgumentException('Data source identifier must be a string'); } $filters = array_merge($this->defaultDataSourceFilters(), $this->dataSourceFilters); if (isset($filters[$sourceIdent])) { return $filters[$sourceIdent]; } return null; }
php
public function dataSourceFilter($sourceIdent) { if (!is_string($sourceIdent)) { throw new InvalidArgumentException('Data source identifier must be a string'); } $filters = array_merge($this->defaultDataSourceFilters(), $this->dataSourceFilters); if (isset($filters[$sourceIdent])) { return $filters[$sourceIdent]; } return null; }
[ "public", "function", "dataSourceFilter", "(", "$", "sourceIdent", ")", "{", "if", "(", "!", "is_string", "(", "$", "sourceIdent", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Data source identifier must be a string'", ")", ";", "}", "$", "f...
Retrieve the callable filter for the given data source. @param string $sourceIdent A data source identifier. @throws InvalidArgumentException If the data source is invalid. @return callable|null Returns a callable variable.
[ "Retrieve", "the", "callable", "filter", "for", "the", "given", "data", "source", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminWidget.php#L318-L331
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminModule.php
AdminModule.setup
public function setup() { // Hack: skip if the request does not start with '/admin' $container = $this->app()->getContainer(); if (substr(ltrim($container['request']->getUri()->getPath(), '/'), 0, 5) !== 'admin') { return $this; } // A session is necessary for the admin module if (session_id() === '') { session_start(); } $container->register(new AdminServiceProvider()); $module = $this; $container['charcoal/admin/module'] = function () use ($module) { return $module; }; $adminConfig = $container['admin/config']; $this->setConfig($adminConfig); $groupIdent = '/'.trim($adminConfig['base_path'], '/'); // Add the route group $this->app()->group($groupIdent, 'charcoal/admin/module:setupRoutes') ->add('charcoal/admin/module:setupHandlers'); return $this; }
php
public function setup() { // Hack: skip if the request does not start with '/admin' $container = $this->app()->getContainer(); if (substr(ltrim($container['request']->getUri()->getPath(), '/'), 0, 5) !== 'admin') { return $this; } // A session is necessary for the admin module if (session_id() === '') { session_start(); } $container->register(new AdminServiceProvider()); $module = $this; $container['charcoal/admin/module'] = function () use ($module) { return $module; }; $adminConfig = $container['admin/config']; $this->setConfig($adminConfig); $groupIdent = '/'.trim($adminConfig['base_path'], '/'); // Add the route group $this->app()->group($groupIdent, 'charcoal/admin/module:setupRoutes') ->add('charcoal/admin/module:setupHandlers'); return $this; }
[ "public", "function", "setup", "(", ")", "{", "// Hack: skip if the request does not start with '/admin'", "$", "container", "=", "$", "this", "->", "app", "(", ")", "->", "getContainer", "(", ")", ";", "if", "(", "substr", "(", "ltrim", "(", "$", "container",...
Charcoal Administration Setup. This module is bound to the `/admin` URL. ## Provides - `charcoal/admin/module` An instance of this module - Exact type: `\Charcoal\Admin\AdminModule` - which implements `\Charcoal\Module\ModuleInterface` ## Dependencies - `charcoal/config` Provided by \Charcoal\CharcoalModule @return AdminModule Chainable
[ "Charcoal", "Administration", "Setup", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminModule.php#L37-L67
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/AdminModule.php
AdminModule.setupRoutes
public function setupRoutes() { if ($this->routeManager === null) { parent::setupRoutes(); // Serve the Admin's "Not Found" handler for the Admin's route group. $this->app()->any('{catchall:.*}', 'notFoundHandler'); } return $this; }
php
public function setupRoutes() { if ($this->routeManager === null) { parent::setupRoutes(); // Serve the Admin's "Not Found" handler for the Admin's route group. $this->app()->any('{catchall:.*}', 'notFoundHandler'); } return $this; }
[ "public", "function", "setupRoutes", "(", ")", "{", "if", "(", "$", "this", "->", "routeManager", "===", "null", ")", "{", "parent", "::", "setupRoutes", "(", ")", ";", "// Serve the Admin's \"Not Found\" handler for the Admin's route group.", "$", "this", "->", "...
Set up the module's routes and handlers. @return AdminModule Chainable
[ "Set", "up", "the", "module", "s", "routes", "and", "handlers", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/AdminModule.php#L74-L84
train
acquia/commerce-manager
modules/acm_cart/src/Access/CartAccess.php
CartAccess.access
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) { return AccessResult::allowedIf( $this->cartStorage->getCart() && $this->cartStorage->getCart()->getCartItemsCount() > 0 ); }
php
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) { return AccessResult::allowedIf( $this->cartStorage->getCart() && $this->cartStorage->getCart()->getCartItemsCount() > 0 ); }
[ "public", "function", "access", "(", "Route", "$", "route", ",", "RouteMatchInterface", "$", "route_match", ",", "AccountInterface", "$", "account", ")", "{", "return", "AccessResult", "::", "allowedIf", "(", "$", "this", "->", "cartStorage", "->", "getCart", ...
Determine access by ensuring that the cart object has items. @param \Symfony\Component\Routing\Route $route The route to check against. @param \Drupal\Core\Routing\RouteMatchInterface $route_match The parametrized route. @param \Drupal\Core\Session\AccountInterface $account The currently logged in account. @return \Drupal\Core\Access\AccessResultInterface The access result.
[ "Determine", "access", "by", "ensuring", "that", "the", "cart", "object", "has", "items", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_cart/src/Access/CartAccess.php#L56-L60
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.isProductInStock
public function isProductInStock(SKU $sku) { $sku_string = $sku->getSku(); $static = &drupal_static(self::class . '_' . __FUNCTION__, []); if (isset($static[$sku_string])) { return $static[$sku_string]; } // Initialise static value with FALSE. $static[$sku_string] = FALSE; $stock = $this->getStock($sku_string); if (empty($stock['status'])) { return FALSE; } // Check status + quantity of children if configurable. switch ($sku->bundle()) { case 'configurable': // For configurable product to be in-stock only one in-stock child // is enough. foreach ($sku->get('field_configured_skus')->getValue() as $child) { if (empty($child['value'])) { continue; } $child_sku = SKU::loadFromSku($child['value']); if ($child_sku instanceof SKU) { if ($this->getStockQuantity($child_sku->getSku()) > 0) { $static[$sku_string] = TRUE; break; } } } break; case 'simple': default: $static[$sku_string] = (bool) $this->getStockQuantity($sku->getSku()); break; } return $static[$sku_string]; }
php
public function isProductInStock(SKU $sku) { $sku_string = $sku->getSku(); $static = &drupal_static(self::class . '_' . __FUNCTION__, []); if (isset($static[$sku_string])) { return $static[$sku_string]; } // Initialise static value with FALSE. $static[$sku_string] = FALSE; $stock = $this->getStock($sku_string); if (empty($stock['status'])) { return FALSE; } // Check status + quantity of children if configurable. switch ($sku->bundle()) { case 'configurable': // For configurable product to be in-stock only one in-stock child // is enough. foreach ($sku->get('field_configured_skus')->getValue() as $child) { if (empty($child['value'])) { continue; } $child_sku = SKU::loadFromSku($child['value']); if ($child_sku instanceof SKU) { if ($this->getStockQuantity($child_sku->getSku()) > 0) { $static[$sku_string] = TRUE; break; } } } break; case 'simple': default: $static[$sku_string] = (bool) $this->getStockQuantity($sku->getSku()); break; } return $static[$sku_string]; }
[ "public", "function", "isProductInStock", "(", "SKU", "$", "sku", ")", "{", "$", "sku_string", "=", "$", "sku", "->", "getSku", "(", ")", ";", "$", "static", "=", "&", "drupal_static", "(", "self", "::", "class", ".", "'_'", ".", "__FUNCTION__", ",", ...
Check if product is in stock. @param \Drupal\acm_sku\Entity\SKU $sku SKU Entity. @return bool TRUE if product is in stock.
[ "Check", "if", "product", "is", "in", "stock", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L115-L158
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.getStockQuantity
public function getStockQuantity(string $sku) { $stock = $this->getStock($sku); if (empty($stock['status'])) { return 0; } // @TODO: For now there is no scenario in which we have quantity in float. // We have kept the database field to match what is there in MDC and code // can be updated later to match that. Casting it to int for now. return (int) $stock['quantity']; }
php
public function getStockQuantity(string $sku) { $stock = $this->getStock($sku); if (empty($stock['status'])) { return 0; } // @TODO: For now there is no scenario in which we have quantity in float. // We have kept the database field to match what is there in MDC and code // can be updated later to match that. Casting it to int for now. return (int) $stock['quantity']; }
[ "public", "function", "getStockQuantity", "(", "string", "$", "sku", ")", "{", "$", "stock", "=", "$", "this", "->", "getStock", "(", "$", "sku", ")", ";", "if", "(", "empty", "(", "$", "stock", "[", "'status'", "]", ")", ")", "{", "return", "0", ...
Get stock quantity. @param string $sku SKU string. @return int Quantity, 0 if status flag is set to false.
[ "Get", "stock", "quantity", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L169-L180
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.getStock
public function getStock(string $sku) { $query = $this->connection->select('acm_sku_stock'); $query->fields('acm_sku_stock'); $query->condition('sku', $sku); $result = $query->execute()->fetchAll(); // We may not have any entry. if (empty($result)) { return []; } // Log if more than one found. if (count($result) > 1) { $this->logger->error('Duplicate entries found for stock of sku @sku.', [ '@sku' => $sku, ]); } // Get the first result. $data = reset($result); return (array) $data; }
php
public function getStock(string $sku) { $query = $this->connection->select('acm_sku_stock'); $query->fields('acm_sku_stock'); $query->condition('sku', $sku); $result = $query->execute()->fetchAll(); // We may not have any entry. if (empty($result)) { return []; } // Log if more than one found. if (count($result) > 1) { $this->logger->error('Duplicate entries found for stock of sku @sku.', [ '@sku' => $sku, ]); } // Get the first result. $data = reset($result); return (array) $data; }
[ "public", "function", "getStock", "(", "string", "$", "sku", ")", "{", "$", "query", "=", "$", "this", "->", "connection", "->", "select", "(", "'acm_sku_stock'", ")", ";", "$", "query", "->", "fields", "(", "'acm_sku_stock'", ")", ";", "$", "query", "...
Get current stock data for SKU from DB. @param string $sku SKU string. @return array Stock data with keys [sku, status, quantity].
[ "Get", "current", "stock", "data", "for", "SKU", "from", "DB", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L191-L213
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.refreshStock
public function refreshStock(string $sku) { try { $stock = $this->apiWrapper->skuStockCheck($sku); $this->processStockMessage($stock); } catch (\Exception $e) { $this->logger->error('Exception occurred while resetting stock for sku: @sku, message: @message', [ '@sku' => $sku, '@message' => $e->getMessage(), ]); } }
php
public function refreshStock(string $sku) { try { $stock = $this->apiWrapper->skuStockCheck($sku); $this->processStockMessage($stock); } catch (\Exception $e) { $this->logger->error('Exception occurred while resetting stock for sku: @sku, message: @message', [ '@sku' => $sku, '@message' => $e->getMessage(), ]); } }
[ "public", "function", "refreshStock", "(", "string", "$", "sku", ")", "{", "try", "{", "$", "stock", "=", "$", "this", "->", "apiWrapper", "->", "skuStockCheck", "(", "$", "sku", ")", ";", "$", "this", "->", "processStockMessage", "(", "$", "stock", ")...
Refresh stock for an SKU from API. @param string $sku SKU string.
[ "Refresh", "stock", "for", "an", "SKU", "from", "API", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L221-L232
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.updateStock
public function updateStock($sku, $quantity, $status) { // Update the stock now. $this->acquireLock($sku); // First try to check if stock changed. $current = $this->getStock($sku); // Update only if value changed. if (empty($current) || $current['status'] != $status || $current['quantity'] != $quantity) { $new = [ 'quantity' => $quantity, 'status' => $status, ]; $this->connection->merge('acm_sku_stock') ->key(['sku' => $sku]) ->fields($new) ->execute(); $status_changed = $current ? $this->isStockStatusChanged($current, $new) : TRUE; $sku_entity = SKU::loadFromSku($sku); if ($sku_entity instanceof SKUInterface) { $low_quantity = $this->isQuantityLow($new); $event = new StockUpdatedEvent($sku_entity, $status_changed, $low_quantity); $this->dispatcher->dispatch(StockUpdatedEvent::EVENT_NAME, $event); } return $status_changed; } $this->releaseLock($sku); return FALSE; }
php
public function updateStock($sku, $quantity, $status) { // Update the stock now. $this->acquireLock($sku); // First try to check if stock changed. $current = $this->getStock($sku); // Update only if value changed. if (empty($current) || $current['status'] != $status || $current['quantity'] != $quantity) { $new = [ 'quantity' => $quantity, 'status' => $status, ]; $this->connection->merge('acm_sku_stock') ->key(['sku' => $sku]) ->fields($new) ->execute(); $status_changed = $current ? $this->isStockStatusChanged($current, $new) : TRUE; $sku_entity = SKU::loadFromSku($sku); if ($sku_entity instanceof SKUInterface) { $low_quantity = $this->isQuantityLow($new); $event = new StockUpdatedEvent($sku_entity, $status_changed, $low_quantity); $this->dispatcher->dispatch(StockUpdatedEvent::EVENT_NAME, $event); } return $status_changed; } $this->releaseLock($sku); return FALSE; }
[ "public", "function", "updateStock", "(", "$", "sku", ",", "$", "quantity", ",", "$", "status", ")", "{", "// Update the stock now.", "$", "this", "->", "acquireLock", "(", "$", "sku", ")", ";", "// First try to check if stock changed.", "$", "current", "=", "...
Update stock data for particular sku. @param string $sku SKU. @param int|float $quantity Quantity. @param int $status Stock status. @return bool TRUE if stock status changed. @throws \Exception
[ "Update", "stock", "data", "for", "particular", "sku", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L249-L284
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.processStockMessage
public function processStockMessage(array $stock, $store_id = 0) { // Sanity check. if (!isset($stock['sku']) || !strlen($stock['sku'])) { $this->logger->error('Invalid or empty product SKU. Stock message: @message', [ '@message' => json_encode($stock), ]); return; } $langcode = NULL; if (empty($store_id) && isset($stock['store_id'])) { $store_id = $stock['store_id']; } // Check for stock is valid for current site. // If store id not available, we consider it as valid message. if ($store_id) { $langcode = $this->i18nHelper->getLangcodeFromStoreId($store_id); if (empty($langcode)) { // It could be for a different store/website, don't do anything. $this->logger->info('Ignored stock message for different store. Message: @message', [ '@message' => json_encode($stock), ]); return; } } // We get qty in product data and quantity in stock push or from stock api. $quantity = array_key_exists('qty', $stock) ? $stock['qty'] : $stock['quantity']; $stock_status = isset($stock['is_in_stock']) ? (int) $stock['is_in_stock'] : 1; $changed = $this->updateStock($stock['sku'], $quantity, $stock_status); $this->logger->info('@operation stock for sku @sku. Message: @message', [ '@operation' => $changed ? 'Updated' : 'Processed', '@sku' => $stock['sku'], '@message' => json_encode($stock), ]); }
php
public function processStockMessage(array $stock, $store_id = 0) { // Sanity check. if (!isset($stock['sku']) || !strlen($stock['sku'])) { $this->logger->error('Invalid or empty product SKU. Stock message: @message', [ '@message' => json_encode($stock), ]); return; } $langcode = NULL; if (empty($store_id) && isset($stock['store_id'])) { $store_id = $stock['store_id']; } // Check for stock is valid for current site. // If store id not available, we consider it as valid message. if ($store_id) { $langcode = $this->i18nHelper->getLangcodeFromStoreId($store_id); if (empty($langcode)) { // It could be for a different store/website, don't do anything. $this->logger->info('Ignored stock message for different store. Message: @message', [ '@message' => json_encode($stock), ]); return; } } // We get qty in product data and quantity in stock push or from stock api. $quantity = array_key_exists('qty', $stock) ? $stock['qty'] : $stock['quantity']; $stock_status = isset($stock['is_in_stock']) ? (int) $stock['is_in_stock'] : 1; $changed = $this->updateStock($stock['sku'], $quantity, $stock_status); $this->logger->info('@operation stock for sku @sku. Message: @message', [ '@operation' => $changed ? 'Updated' : 'Processed', '@sku' => $stock['sku'], '@message' => json_encode($stock), ]); }
[ "public", "function", "processStockMessage", "(", "array", "$", "stock", ",", "$", "store_id", "=", "0", ")", "{", "// Sanity check.", "if", "(", "!", "isset", "(", "$", "stock", "[", "'sku'", "]", ")", "||", "!", "strlen", "(", "$", "stock", "[", "'...
Process stock message received in API. @param array $stock Stock data for particular SKU. @param int $store_id Store ID. @throws \Exception
[ "Process", "stock", "message", "received", "in", "API", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L296-L338
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.acquireLock
private function acquireLock(string $sku) { $lock_key = self::class . ':' . $sku; do { $lock_acquired = $this->lock->acquire($lock_key); // Sleep for half a second before trying again. if (!$lock_acquired) { usleep(500000); } } while (!$lock_acquired); }
php
private function acquireLock(string $sku) { $lock_key = self::class . ':' . $sku; do { $lock_acquired = $this->lock->acquire($lock_key); // Sleep for half a second before trying again. if (!$lock_acquired) { usleep(500000); } } while (!$lock_acquired); }
[ "private", "function", "acquireLock", "(", "string", "$", "sku", ")", "{", "$", "lock_key", "=", "self", "::", "class", ".", "':'", ".", "$", "sku", ";", "do", "{", "$", "lock_acquired", "=", "$", "this", "->", "lock", "->", "acquire", "(", "$", "l...
Helper function to acquire lock. @param string $sku SKU string.
[ "Helper", "function", "to", "acquire", "lock", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L346-L356
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.releaseLock
private function releaseLock(string $sku) { $lock_key = self::class . ':' . $sku; $this->lock->release($lock_key); }
php
private function releaseLock(string $sku) { $lock_key = self::class . ':' . $sku; $this->lock->release($lock_key); }
[ "private", "function", "releaseLock", "(", "string", "$", "sku", ")", "{", "$", "lock_key", "=", "self", "::", "class", ".", "':'", ".", "$", "sku", ";", "$", "this", "->", "lock", "->", "release", "(", "$", "lock_key", ")", ";", "}" ]
Helper function to release lock. @param string $sku SKU string.
[ "Helper", "function", "to", "release", "lock", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L364-L367
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.isStockStatusChanged
private function isStockStatusChanged(array $old, array $new) { if ($old['status'] != $new['status']) { return TRUE; } $had_quantity = (bool) $old['quantity']; $has_quantity = (bool) $new['quantity']; // Either it was zero before or zero now and status says in stock, // we consider it is changed. if ($new['status'] && $had_quantity != $has_quantity) { return TRUE; } return FALSE; }
php
private function isStockStatusChanged(array $old, array $new) { if ($old['status'] != $new['status']) { return TRUE; } $had_quantity = (bool) $old['quantity']; $has_quantity = (bool) $new['quantity']; // Either it was zero before or zero now and status says in stock, // we consider it is changed. if ($new['status'] && $had_quantity != $has_quantity) { return TRUE; } return FALSE; }
[ "private", "function", "isStockStatusChanged", "(", "array", "$", "old", ",", "array", "$", "new", ")", "{", "if", "(", "$", "old", "[", "'status'", "]", "!=", "$", "new", "[", "'status'", "]", ")", "{", "return", "TRUE", ";", "}", "$", "had_quantity...
Get field code for which value is requested. @param array $old Old stock. @param array $new New stock. @return bool TRUE if stock status changed.
[ "Get", "field", "code", "for", "which", "value", "is", "requested", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L380-L395
train
acquia/commerce-manager
modules/acm_sku/src/StockManager.php
StockManager.removeStockEntry
public function removeStockEntry(string $sku) { if (empty($sku)) { return; } // Confirm SKU is not available in any language. $query = $this->connection->select('acm_sku_field_data', 'sku'); $query->condition('sku', $sku); $query->addField('sku', 'sku'); $result = $query->execute()->fetchAssoc(); if (!empty($result)) { return; } // Remove stock only after SKU is removed in all the languages. $this->connection->delete('acm_sku_stock') ->condition('sku', $sku) ->execute(); }
php
public function removeStockEntry(string $sku) { if (empty($sku)) { return; } // Confirm SKU is not available in any language. $query = $this->connection->select('acm_sku_field_data', 'sku'); $query->condition('sku', $sku); $query->addField('sku', 'sku'); $result = $query->execute()->fetchAssoc(); if (!empty($result)) { return; } // Remove stock only after SKU is removed in all the languages. $this->connection->delete('acm_sku_stock') ->condition('sku', $sku) ->execute(); }
[ "public", "function", "removeStockEntry", "(", "string", "$", "sku", ")", "{", "if", "(", "empty", "(", "$", "sku", ")", ")", "{", "return", ";", "}", "// Confirm SKU is not available in any language.", "$", "query", "=", "$", "this", "->", "connection", "->...
Remove stock entry. @param string $sku SKU for which stock entry needs to be removed.
[ "Remove", "stock", "entry", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/StockManager.php#L425-L444
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/AbstractPropertyDisplay.php
AbstractPropertyDisplay.displayName
public function displayName() { if ($this->displayName) { $name = $this->displayName; } else { $name = $this->propertyIdent(); } if ($this->p()->l10n()) { $name .= '['.$this->lang().']'; } if ($this->multiple()) { $name .= '[]'; } return $name; }
php
public function displayName() { if ($this->displayName) { $name = $this->displayName; } else { $name = $this->propertyIdent(); } if ($this->p()->l10n()) { $name .= '['.$this->lang().']'; } if ($this->multiple()) { $name .= '[]'; } return $name; }
[ "public", "function", "displayName", "(", ")", "{", "if", "(", "$", "this", "->", "displayName", ")", "{", "$", "name", "=", "$", "this", "->", "displayName", ";", "}", "else", "{", "$", "name", "=", "$", "this", "->", "propertyIdent", "(", ")", ";...
Retrieve the display name. The input name should always be the property's ident. @return string
[ "Retrieve", "the", "display", "name", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/AbstractPropertyDisplay.php#L302-L319
train
acquia/commerce-manager
modules/acm/src/APIHelper.php
APIHelper.cleanCustomerData
public function cleanCustomerData(array $customer) { if (isset($customer['customer_id'])) { $customer['customer_id'] = (string) $customer['customer_id']; } if (isset($customer['addresses'])) { // When deleting an address need to re-index array. $customer['addresses'] = array_values($customer['addresses']); foreach ($customer['addresses'] as $delta => $address) { $address = (array) $address; $customer['addresses'][$delta] = $this->cleanCustomerAddress($address); } } return $customer; }
php
public function cleanCustomerData(array $customer) { if (isset($customer['customer_id'])) { $customer['customer_id'] = (string) $customer['customer_id']; } if (isset($customer['addresses'])) { // When deleting an address need to re-index array. $customer['addresses'] = array_values($customer['addresses']); foreach ($customer['addresses'] as $delta => $address) { $address = (array) $address; $customer['addresses'][$delta] = $this->cleanCustomerAddress($address); } } return $customer; }
[ "public", "function", "cleanCustomerData", "(", "array", "$", "customer", ")", "{", "if", "(", "isset", "(", "$", "customer", "[", "'customer_id'", "]", ")", ")", "{", "$", "customer", "[", "'customer_id'", "]", "=", "(", "string", ")", "$", "customer", ...
Clean customer data before sending to API. @param array $customer Customer data. @return array Cleaned customer data.
[ "Clean", "customer", "data", "before", "sending", "to", "API", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/APIHelper.php#L23-L38
train
acquia/commerce-manager
modules/acm/src/APIHelper.php
APIHelper.cleanCustomerAddress
public function cleanCustomerAddress(array $address) { if (isset($address['customer_address_id']) && empty($address['address_id'])) { $address['address_id'] = $address['customer_address_id']; } return $this->cleanAddress($address); }
php
public function cleanCustomerAddress(array $address) { if (isset($address['customer_address_id']) && empty($address['address_id'])) { $address['address_id'] = $address['customer_address_id']; } return $this->cleanAddress($address); }
[ "public", "function", "cleanCustomerAddress", "(", "array", "$", "address", ")", "{", "if", "(", "isset", "(", "$", "address", "[", "'customer_address_id'", "]", ")", "&&", "empty", "(", "$", "address", "[", "'address_id'", "]", ")", ")", "{", "$", "addr...
Get cleaned customer address. @param array $address Customer address. @return array Cleaned customer address.
[ "Get", "cleaned", "customer", "address", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/APIHelper.php#L49-L55
train
acquia/commerce-manager
modules/acm/src/APIHelper.php
APIHelper.cleanCartAddress
public function cleanCartAddress($address) { $address = (array) $address; $address = $this->cleanAddress($address); if (isset($address['customer_address_id'])) { $address['customer_address_id'] = (int) $address['customer_address_id']; } // Never send address_id in API request, it confuses Magento. if (isset($address['address_id'])) { unset($address['address_id']); } return $address; }
php
public function cleanCartAddress($address) { $address = (array) $address; $address = $this->cleanAddress($address); if (isset($address['customer_address_id'])) { $address['customer_address_id'] = (int) $address['customer_address_id']; } // Never send address_id in API request, it confuses Magento. if (isset($address['address_id'])) { unset($address['address_id']); } return $address; }
[ "public", "function", "cleanCartAddress", "(", "$", "address", ")", "{", "$", "address", "=", "(", "array", ")", "$", "address", ";", "$", "address", "=", "$", "this", "->", "cleanAddress", "(", "$", "address", ")", ";", "if", "(", "isset", "(", "$",...
Get cleaned cart address. @param mixed $address Cart address object/array. @return array Cleaned cart address.
[ "Get", "cleaned", "cart", "address", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/APIHelper.php#L66-L81
train
acquia/commerce-manager
modules/acm/src/APIHelper.php
APIHelper.normaliseExtension
public function normaliseExtension($data) { if (is_object($data)) { if (isset($data->extension)) { $data->extension = (object) $data->extension; } } elseif (is_array($data)) { if (isset($data['extension'])) { $data['extension'] = (object) $data['extension']; } } return $data; }
php
public function normaliseExtension($data) { if (is_object($data)) { if (isset($data->extension)) { $data->extension = (object) $data->extension; } } elseif (is_array($data)) { if (isset($data['extension'])) { $data['extension'] = (object) $data['extension']; } } return $data; }
[ "public", "function", "normaliseExtension", "(", "$", "data", ")", "{", "if", "(", "is_object", "(", "$", "data", ")", ")", "{", "if", "(", "isset", "(", "$", "data", "->", "extension", ")", ")", "{", "$", "data", "->", "extension", "=", "(", "obje...
Extensions must always be objects and not arrays. @param mixed $data Array/Object data. @return array Data in same type but with extension as object.
[ "Extensions", "must", "always", "be", "objects", "and", "not", "arrays", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/APIHelper.php#L117-L130
train
acquia/commerce-manager
modules/acm/src/APIHelper.php
APIHelper.cleanCart
public function cleanCart($cart) { // Check if there's a customer ID and remove it if it's empty. if (isset($cart->customer_id) && empty($cart->customer_id)) { unset($cart->customer_id); } elseif (isset($cart->customer_id)) { $cart->customer_id = (string) $cart->customer_id; } // Check if there's a customer email and remove it if it's empty. if (isset($cart->customer_email) && empty($cart->customer_email)) { unset($cart->customer_email); } // Don't tell conductor our stored totals for no reason. if (isset($cart->totals)) { unset($cart->totals); } // Cart extensions must always be objects and not arrays. if (isset($cart->carrier)) { $cart->carrier = $this->normaliseExtension($cart->carrier); } // Remove shipping address if carrier not set. else { unset($cart->shipping); } // Cart constructor sets cart to any object passed in, // circumventing ->setBilling() so trap any wayward extension[] here. if (isset($cart->billing)) { $cart->billing = $this->cleanCartAddress($cart->billing); } if (isset($cart->shipping)) { $cart->shipping = $this->cleanCartAddress($cart->shipping); } // Never send response_message back. if (isset($cart->response_message)) { unset($cart->response_message); } // When we remove an item from cart, we have to reset the keys to have // proper indexed array. if (isset($cart->items)) { $cart->items = array_values($cart->items); foreach ($cart->items as &$item) { $item['sku'] = (string) $item['sku']; } } return $cart; }
php
public function cleanCart($cart) { // Check if there's a customer ID and remove it if it's empty. if (isset($cart->customer_id) && empty($cart->customer_id)) { unset($cart->customer_id); } elseif (isset($cart->customer_id)) { $cart->customer_id = (string) $cart->customer_id; } // Check if there's a customer email and remove it if it's empty. if (isset($cart->customer_email) && empty($cart->customer_email)) { unset($cart->customer_email); } // Don't tell conductor our stored totals for no reason. if (isset($cart->totals)) { unset($cart->totals); } // Cart extensions must always be objects and not arrays. if (isset($cart->carrier)) { $cart->carrier = $this->normaliseExtension($cart->carrier); } // Remove shipping address if carrier not set. else { unset($cart->shipping); } // Cart constructor sets cart to any object passed in, // circumventing ->setBilling() so trap any wayward extension[] here. if (isset($cart->billing)) { $cart->billing = $this->cleanCartAddress($cart->billing); } if (isset($cart->shipping)) { $cart->shipping = $this->cleanCartAddress($cart->shipping); } // Never send response_message back. if (isset($cart->response_message)) { unset($cart->response_message); } // When we remove an item from cart, we have to reset the keys to have // proper indexed array. if (isset($cart->items)) { $cart->items = array_values($cart->items); foreach ($cart->items as &$item) { $item['sku'] = (string) $item['sku']; } } return $cart; }
[ "public", "function", "cleanCart", "(", "$", "cart", ")", "{", "// Check if there's a customer ID and remove it if it's empty.", "if", "(", "isset", "(", "$", "cart", "->", "customer_id", ")", "&&", "empty", "(", "$", "cart", "->", "customer_id", ")", ")", "{", ...
Clean up cart data. @param object $cart Cart object. @return object Cleaned cart object.
[ "Clean", "up", "cart", "data", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/APIHelper.php#L141-L195
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Script/User/ResetPasswordScript.php
ResetPasswordScript.defaultArguments
public function defaultArguments() { $arguments = [ 'email' => [ 'prefix' => 'e', 'longPrefix' => 'email', 'description' => 'The user email' ], 'password' => [ 'prefix' => 'p', 'longPrefix' => 'password', 'description' => 'The user password', 'inputType' => 'password' ], 'sendEmail' => [ 'longPrefix' => 'send-email', 'description' => 'If set, an email will be sent to the user.', 'noValue' => true, 'defaultValue' => false ] ]; $arguments = array_merge(parent::defaultArguments(), $arguments); return $arguments; }
php
public function defaultArguments() { $arguments = [ 'email' => [ 'prefix' => 'e', 'longPrefix' => 'email', 'description' => 'The user email' ], 'password' => [ 'prefix' => 'p', 'longPrefix' => 'password', 'description' => 'The user password', 'inputType' => 'password' ], 'sendEmail' => [ 'longPrefix' => 'send-email', 'description' => 'If set, an email will be sent to the user.', 'noValue' => true, 'defaultValue' => false ] ]; $arguments = array_merge(parent::defaultArguments(), $arguments); return $arguments; }
[ "public", "function", "defaultArguments", "(", ")", "{", "$", "arguments", "=", "[", "'email'", "=>", "[", "'prefix'", "=>", "'e'", ",", "'longPrefix'", "=>", "'email'", ",", "'description'", "=>", "'The user email'", "]", ",", "'password'", "=>", "[", "'pre...
Retrieve the available default arguments of this action. @link http://climate.thephpleague.com/arguments/ For descriptions of the options for CLImate. @return array
[ "Retrieve", "the", "available", "default", "arguments", "of", "this", "action", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Script/User/ResetPasswordScript.php#L36-L61
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/AuthActionTrait.php
AuthActionTrait.loadUser
protected function loadUser($handle) { if (!$handle) { return null; } // Try to get user by ID $user = $this->modelFactory()->create(User::class); $user->load($handle); if ($user->id() !== null) { return $user; } // Try to get user by email $user->loadFrom('email', $handle); if ($user->id() !== null) { return $user; } return null; }
php
protected function loadUser($handle) { if (!$handle) { return null; } // Try to get user by ID $user = $this->modelFactory()->create(User::class); $user->load($handle); if ($user->id() !== null) { return $user; } // Try to get user by email $user->loadFrom('email', $handle); if ($user->id() !== null) { return $user; } return null; }
[ "protected", "function", "loadUser", "(", "$", "handle", ")", "{", "if", "(", "!", "$", "handle", ")", "{", "return", "null", ";", "}", "// Try to get user by ID", "$", "user", "=", "$", "this", "->", "modelFactory", "(", ")", "->", "create", "(", "Use...
Retrieve the user with the given login handle. @param string $handle An ID or email address. @return User|null Returns the user object instance or NULL.
[ "Retrieve", "the", "user", "with", "the", "given", "login", "handle", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/AuthActionTrait.php#L24-L44
train
acquia/commerce-manager
modules/acm/src/Access/VersionAccessCheck.php
VersionAccessCheck.access
public function access() { $version = $this->configFactory->get('acm.connector')->get('api_version'); if (($version === 'v2') && ($this->account->hasPermission('access commerce administration pages'))) { return AccessResult::allowed(); } return AccessResult::forbidden(); }
php
public function access() { $version = $this->configFactory->get('acm.connector')->get('api_version'); if (($version === 'v2') && ($this->account->hasPermission('access commerce administration pages'))) { return AccessResult::allowed(); } return AccessResult::forbidden(); }
[ "public", "function", "access", "(", ")", "{", "$", "version", "=", "$", "this", "->", "configFactory", "->", "get", "(", "'acm.connector'", ")", "->", "get", "(", "'api_version'", ")", ";", "if", "(", "(", "$", "version", "===", "'v2'", ")", "&&", "...
Check if v2 is set up and user can access commerce admin pages. @return \Drupal\Core\Access\AccessResultInterface The access result.
[ "Check", "if", "v2", "is", "set", "up", "and", "user", "can", "access", "commerce", "admin", "pages", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/Access/VersionAccessCheck.php#L48-L54
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/SelectInput.php
SelectInput.selectOptions
public function selectOptions() { if ($this->selectOptions === null) { $this->selectOptions = $this->defaultSelectOptions(); } return $this->selectOptions; }
php
public function selectOptions() { if ($this->selectOptions === null) { $this->selectOptions = $this->defaultSelectOptions(); } return $this->selectOptions; }
[ "public", "function", "selectOptions", "(", ")", "{", "if", "(", "$", "this", "->", "selectOptions", "===", "null", ")", "{", "$", "this", "->", "selectOptions", "=", "$", "this", "->", "defaultSelectOptions", "(", ")", ";", "}", "return", "$", "this", ...
Retrieve the select picker's options. @return array
[ "Retrieve", "the", "select", "picker", "s", "options", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/SelectInput.php#L140-L147
train
acquia/commerce-manager
modules/acm_checkout/src/Plugin/Block/CheckoutProgressBlock.php
CheckoutProgressBlock.build
public function build() { $route_name = $this->routeMatch->getRouteName(); if ($route_name !== 'acm_checkout.form') { return []; } // Load the CheckoutFlow plugin. $config = \Drupal::config('acm_checkout.settings'); $checkout_flow_plugin = $config->get('checkout_flow_plugin') ?: 'multistep_default'; $plugin_manager = \Drupal::service('plugin.manager.acm_checkout_flow'); $checkout_flow = $plugin_manager->createInstance($checkout_flow_plugin, []); // Build the steps sent to the template. $steps = []; $visible_steps = array_filter($checkout_flow->getVisibleSteps(), function ($step_definition) { return (!isset($step_definition['hide_from_progress'])); }); $visible_step_ids = array_keys($visible_steps); $current_step_id = $checkout_flow->getStepId(); $current_step_index = array_search($current_step_id, $visible_step_ids); // Get last step completed in the cart. $cart = $this->cartStorage; $cart_step_id = $cart->getCheckoutStep(); $cart_step_index = array_search($cart_step_id, $visible_step_ids); $index = 0; foreach ($visible_steps as $step_id => $step_definition) { $is_link = FALSE; $completed = FALSE; if ($index < $current_step_index) { $position = 'previous'; } elseif ($index == $current_step_index) { $position = 'current'; } else { $position = 'next'; } $label = $step_definition['label']; // Add a class if this step has been completed already. if ($index < $cart_step_index) { $completed = TRUE; } // Set the label to a link if this step has already been completed so that // the progress bar can be used as a sort of navigation. if ($index <= $cart_step_index && $index !== $current_step_index) { $is_link = TRUE; $label = Link::createFromRoute($label, 'acm_checkout.form', [ 'step' => $step_id, ])->toString(); } $steps[] = [ 'id' => $step_id, 'label' => $label, 'position' => $position, 'completed' => $completed, 'is_link' => $is_link, ]; $index++; } return [ '#attached' => [ 'library' => ['acm_checkout/checkout_progress'], ], '#theme' => 'acm_checkout_progress', '#steps' => $steps, ]; }
php
public function build() { $route_name = $this->routeMatch->getRouteName(); if ($route_name !== 'acm_checkout.form') { return []; } // Load the CheckoutFlow plugin. $config = \Drupal::config('acm_checkout.settings'); $checkout_flow_plugin = $config->get('checkout_flow_plugin') ?: 'multistep_default'; $plugin_manager = \Drupal::service('plugin.manager.acm_checkout_flow'); $checkout_flow = $plugin_manager->createInstance($checkout_flow_plugin, []); // Build the steps sent to the template. $steps = []; $visible_steps = array_filter($checkout_flow->getVisibleSteps(), function ($step_definition) { return (!isset($step_definition['hide_from_progress'])); }); $visible_step_ids = array_keys($visible_steps); $current_step_id = $checkout_flow->getStepId(); $current_step_index = array_search($current_step_id, $visible_step_ids); // Get last step completed in the cart. $cart = $this->cartStorage; $cart_step_id = $cart->getCheckoutStep(); $cart_step_index = array_search($cart_step_id, $visible_step_ids); $index = 0; foreach ($visible_steps as $step_id => $step_definition) { $is_link = FALSE; $completed = FALSE; if ($index < $current_step_index) { $position = 'previous'; } elseif ($index == $current_step_index) { $position = 'current'; } else { $position = 'next'; } $label = $step_definition['label']; // Add a class if this step has been completed already. if ($index < $cart_step_index) { $completed = TRUE; } // Set the label to a link if this step has already been completed so that // the progress bar can be used as a sort of navigation. if ($index <= $cart_step_index && $index !== $current_step_index) { $is_link = TRUE; $label = Link::createFromRoute($label, 'acm_checkout.form', [ 'step' => $step_id, ])->toString(); } $steps[] = [ 'id' => $step_id, 'label' => $label, 'position' => $position, 'completed' => $completed, 'is_link' => $is_link, ]; $index++; } return [ '#attached' => [ 'library' => ['acm_checkout/checkout_progress'], ], '#theme' => 'acm_checkout_progress', '#steps' => $steps, ]; }
[ "public", "function", "build", "(", ")", "{", "$", "route_name", "=", "$", "this", "->", "routeMatch", "->", "getRouteName", "(", ")", ";", "if", "(", "$", "route_name", "!==", "'acm_checkout.form'", ")", "{", "return", "[", "]", ";", "}", "// Load the C...
Builds the checkout progress block. @return array A render array.
[ "Builds", "the", "checkout", "progress", "block", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_checkout/src/Plugin/Block/CheckoutProgressBlock.php#L77-L149
train
acquia/commerce-manager
modules/acm_exception/src/Form/ExceptionSettingsForm.php
ExceptionSettingsForm.getExceptionScenarios
private function getExceptionScenarios() { $scenarios = []; $api_wrapper_interface = class_implements($this->apiWrapper); if ($api_wrapper_interface) { $scenarios = get_class_methods(array_shift($api_wrapper_interface)); } return $scenarios; }
php
private function getExceptionScenarios() { $scenarios = []; $api_wrapper_interface = class_implements($this->apiWrapper); if ($api_wrapper_interface) { $scenarios = get_class_methods(array_shift($api_wrapper_interface)); } return $scenarios; }
[ "private", "function", "getExceptionScenarios", "(", ")", "{", "$", "scenarios", "=", "[", "]", ";", "$", "api_wrapper_interface", "=", "class_implements", "(", "$", "this", "->", "apiWrapper", ")", ";", "if", "(", "$", "api_wrapper_interface", ")", "{", "$"...
Fetches exception scenarios. Fetches exception scenarios by grabbing the methods required in Drupal\acm\Connector\APIWrapperInterface. @return array Array of scenarios.
[ "Fetches", "exception", "scenarios", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_exception/src/Form/ExceptionSettingsForm.php#L154-L161
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.propertiesOptions
public function propertiesOptions() { if ($this->propertiesOptions === null) { $this->propertiesOptions = $this->defaultPropertiesOptions(); } return $this->propertiesOptions; }
php
public function propertiesOptions() { if ($this->propertiesOptions === null) { $this->propertiesOptions = $this->defaultPropertiesOptions(); } return $this->propertiesOptions; }
[ "public", "function", "propertiesOptions", "(", ")", "{", "if", "(", "$", "this", "->", "propertiesOptions", "===", "null", ")", "{", "$", "this", "->", "propertiesOptions", "=", "$", "this", "->", "defaultPropertiesOptions", "(", ")", ";", "}", "return", ...
Retrieve the property customizations for the collection. @return array|null
[ "Retrieve", "the", "property", "customizations", "for", "the", "collection", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L366-L373
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.viewOptions
public function viewOptions($propertyIdent) { if (!$propertyIdent) { return []; } if ($propertyIdent instanceof PropertyInterface) { $propertyIdent = $propertyIdent->ident(); } $options = $this->propertiesOptions(); if (isset($options[$propertyIdent]['view_options'])) { return $options[$propertyIdent]['view_options']; } else { return []; } }
php
public function viewOptions($propertyIdent) { if (!$propertyIdent) { return []; } if ($propertyIdent instanceof PropertyInterface) { $propertyIdent = $propertyIdent->ident(); } $options = $this->propertiesOptions(); if (isset($options[$propertyIdent]['view_options'])) { return $options[$propertyIdent]['view_options']; } else { return []; } }
[ "public", "function", "viewOptions", "(", "$", "propertyIdent", ")", "{", "if", "(", "!", "$", "propertyIdent", ")", "{", "return", "[", "]", ";", "}", "if", "(", "$", "propertyIdent", "instanceof", "PropertyInterface", ")", "{", "$", "propertyIdent", "=",...
Retrieve the view options for the given property. @param string $propertyIdent The property identifier to lookup. @return array
[ "Retrieve", "the", "view", "options", "for", "the", "given", "property", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L381-L398
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.collectionProperties
public function collectionProperties() { $props = $this->properties(); foreach ($props as $propertyIdent => $property) { $propertyMetadata = $props[$propertyIdent]; $p = $this->propertyFactory()->create($propertyMetadata['type']); $p->setIdent($propertyIdent); $p->setData($propertyMetadata); $options = $this->viewOptions($propertyIdent); $classes = $this->parsePropertyCellClasses($p); if (isset($options['label'])) { $label = $this->translator()->translate($options['label']); } else { $label = strval($p->label()); } $column = [ 'label' => trim($label) ]; if (!isset($column['attr'])) { $column['attr'] = []; } if (isset($options['attr'])) { $column['attr'] = array_merge($column['attr'], $options['attr']); } if (isset($classes)) { if (isset($column['attr']['class'])) { if (is_string($classes)) { $classes = explode(' ', $column['attr']['class']); } if (is_string($column['attr']['class'])) { $column['attr']['class'] = explode(' ', $column['attr']['class']); } $column['attr']['class'] = array_unique(array_merge($column['attr']['class'], $classes)); } else { $column['attr']['class'] = $classes; } unset($classes); } $column['attr'] = html_build_attributes($column['attr']); yield $column; } }
php
public function collectionProperties() { $props = $this->properties(); foreach ($props as $propertyIdent => $property) { $propertyMetadata = $props[$propertyIdent]; $p = $this->propertyFactory()->create($propertyMetadata['type']); $p->setIdent($propertyIdent); $p->setData($propertyMetadata); $options = $this->viewOptions($propertyIdent); $classes = $this->parsePropertyCellClasses($p); if (isset($options['label'])) { $label = $this->translator()->translate($options['label']); } else { $label = strval($p->label()); } $column = [ 'label' => trim($label) ]; if (!isset($column['attr'])) { $column['attr'] = []; } if (isset($options['attr'])) { $column['attr'] = array_merge($column['attr'], $options['attr']); } if (isset($classes)) { if (isset($column['attr']['class'])) { if (is_string($classes)) { $classes = explode(' ', $column['attr']['class']); } if (is_string($column['attr']['class'])) { $column['attr']['class'] = explode(' ', $column['attr']['class']); } $column['attr']['class'] = array_unique(array_merge($column['attr']['class'], $classes)); } else { $column['attr']['class'] = $classes; } unset($classes); } $column['attr'] = html_build_attributes($column['attr']); yield $column; } }
[ "public", "function", "collectionProperties", "(", ")", "{", "$", "props", "=", "$", "this", "->", "properties", "(", ")", ";", "foreach", "(", "$", "props", "as", "$", "propertyIdent", "=>", "$", "property", ")", "{", "$", "propertyMetadata", "=", "$", ...
Properties to display in collection template, and their order, as set in object metadata @return array|Generator
[ "Properties", "to", "display", "in", "collection", "template", "and", "their", "order", "as", "set", "in", "object", "metadata" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L405-L459
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.objectActions
public function objectActions() { $this->rawObjectActions(); $objectActions = []; if (is_array($this->objectActions)) { $objectActions = $this->parseAsObjectActions($this->objectActions); } return $objectActions; }
php
public function objectActions() { $this->rawObjectActions(); $objectActions = []; if (is_array($this->objectActions)) { $objectActions = $this->parseAsObjectActions($this->objectActions); } return $objectActions; }
[ "public", "function", "objectActions", "(", ")", "{", "$", "this", "->", "rawObjectActions", "(", ")", ";", "$", "objectActions", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "this", "->", "objectActions", ")", ")", "{", "$", "objectActions", "...
Retrieve the table's object actions. @return array
[ "Retrieve", "the", "table", "s", "object", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L493-L503
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.rawObjectActions
public function rawObjectActions() { if ($this->objectActions === null) { $parsed = $this->parsedObjectActions; $collectionConfig = $this->collectionConfig(); if (isset($collectionConfig['object_actions'])) { $actions = $collectionConfig['object_actions']; } else { $actions = []; } $this->setObjectActions($actions); $this->parsedObjectActions = $parsed; } if ($this->parsedObjectActions === false) { $this->parsedObjectActions = true; $this->objectActions = $this->createObjectActions($this->objectActions); } return $this->objectActions; }
php
public function rawObjectActions() { if ($this->objectActions === null) { $parsed = $this->parsedObjectActions; $collectionConfig = $this->collectionConfig(); if (isset($collectionConfig['object_actions'])) { $actions = $collectionConfig['object_actions']; } else { $actions = []; } $this->setObjectActions($actions); $this->parsedObjectActions = $parsed; } if ($this->parsedObjectActions === false) { $this->parsedObjectActions = true; $this->objectActions = $this->createObjectActions($this->objectActions); } return $this->objectActions; }
[ "public", "function", "rawObjectActions", "(", ")", "{", "if", "(", "$", "this", "->", "objectActions", "===", "null", ")", "{", "$", "parsed", "=", "$", "this", "->", "parsedObjectActions", ";", "$", "collectionConfig", "=", "$", "this", "->", "collection...
Retrieve the table's object actions without rendering it. @return array
[ "Retrieve", "the", "table", "s", "object", "actions", "without", "rendering", "it", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L510-L533
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.setObjectActions
public function setObjectActions(array $actions) { $this->parsedObjectActions = false; $actions = $this->mergeActions($this->defaultObjectActions(), $actions); /** Enable seamless button group */ if (isset($actions['edit'])) { $actions['edit']['actionType'] = 'seamless'; } $this->objectActions = $actions; return $this; }
php
public function setObjectActions(array $actions) { $this->parsedObjectActions = false; $actions = $this->mergeActions($this->defaultObjectActions(), $actions); /** Enable seamless button group */ if (isset($actions['edit'])) { $actions['edit']['actionType'] = 'seamless'; } $this->objectActions = $actions; return $this; }
[ "public", "function", "setObjectActions", "(", "array", "$", "actions", ")", "{", "$", "this", "->", "parsedObjectActions", "=", "false", ";", "$", "actions", "=", "$", "this", "->", "mergeActions", "(", "$", "this", "->", "defaultObjectActions", "(", ")", ...
Set the table's object actions. @param array $actions One or more actions. @return TableWidget Chainable.
[ "Set", "the", "table", "s", "object", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L541-L555
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.emptyListActions
public function emptyListActions() { $actions = $this->listActions(); $filteredArray = array_filter($actions, function ($action) { return $action['empty']; }); return array_values($filteredArray); }
php
public function emptyListActions() { $actions = $this->listActions(); $filteredArray = array_filter($actions, function ($action) { return $action['empty']; }); return array_values($filteredArray); }
[ "public", "function", "emptyListActions", "(", ")", "{", "$", "actions", "=", "$", "this", "->", "listActions", "(", ")", ";", "$", "filteredArray", "=", "array_filter", "(", "$", "actions", ",", "function", "(", "$", "action", ")", "{", "return", "$", ...
Retrieve the table's empty collection actions. @return array
[ "Retrieve", "the", "table", "s", "empty", "collection", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L630-L639
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.listActions
public function listActions() { if ($this->listActions === null) { $collectionConfig = $this->collectionConfig(); if (isset($collectionConfig['list_actions'])) { $actions = $collectionConfig['list_actions']; } else { $actions = []; } $this->setListActions($actions); } if ($this->parsedListActions === false) { $this->parsedListActions = true; $this->listActions = $this->createListActions($this->listActions); } return $this->listActions; }
php
public function listActions() { if ($this->listActions === null) { $collectionConfig = $this->collectionConfig(); if (isset($collectionConfig['list_actions'])) { $actions = $collectionConfig['list_actions']; } else { $actions = []; } $this->setListActions($actions); } if ($this->parsedListActions === false) { $this->parsedListActions = true; $this->listActions = $this->createListActions($this->listActions); } return $this->listActions; }
[ "public", "function", "listActions", "(", ")", "{", "if", "(", "$", "this", "->", "listActions", "===", "null", ")", "{", "$", "collectionConfig", "=", "$", "this", "->", "collectionConfig", "(", ")", ";", "if", "(", "isset", "(", "$", "collectionConfig"...
Retrieve the table's collection actions. @return array
[ "Retrieve", "the", "table", "s", "collection", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L673-L691
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.objectEditUrl
public function objectEditUrl() { $model = $this->proto(); $url = 'object/edit?main_menu={{ main_menu }}&obj_type='.$this->objType(); if ($model->view()) { $url = $model->render((string)$url); } else { $url = preg_replace('~{{\s*id\s*}}~', $this->currentObjId, $url); } return $url; }
php
public function objectEditUrl() { $model = $this->proto(); $url = 'object/edit?main_menu={{ main_menu }}&obj_type='.$this->objType(); if ($model->view()) { $url = $model->render((string)$url); } else { $url = preg_replace('~{{\s*id\s*}}~', $this->currentObjId, $url); } return $url; }
[ "public", "function", "objectEditUrl", "(", ")", "{", "$", "model", "=", "$", "this", "->", "proto", "(", ")", ";", "$", "url", "=", "'object/edit?main_menu={{ main_menu }}&obj_type='", ".", "$", "this", "->", "objType", "(", ")", ";", "if", "(", "$", "m...
Generate URL for editing an object @return string
[ "Generate", "URL", "for", "editing", "an", "object" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L798-L810
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.objectCreateUrl
public function objectCreateUrl() { $actions = $this->listActions(); if ($actions) { foreach ($actions as $action) { if (isset($action['ident']) && $action['ident'] === 'create') { if (isset($action['url'])) { $model = $this->proto(); if ($model->view()) { $action['url'] = $model->render((string)$action['url']); } else { $action['url'] = preg_replace('~{{\s*id\s*}}~', $this->currentObjId, $action['url']); } return $action['url']; } } } } return $this->objectEditUrl(); }
php
public function objectCreateUrl() { $actions = $this->listActions(); if ($actions) { foreach ($actions as $action) { if (isset($action['ident']) && $action['ident'] === 'create') { if (isset($action['url'])) { $model = $this->proto(); if ($model->view()) { $action['url'] = $model->render((string)$action['url']); } else { $action['url'] = preg_replace('~{{\s*id\s*}}~', $this->currentObjId, $action['url']); } return $action['url']; } } } } return $this->objectEditUrl(); }
[ "public", "function", "objectCreateUrl", "(", ")", "{", "$", "actions", "=", "$", "this", "->", "listActions", "(", ")", ";", "if", "(", "$", "actions", ")", "{", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "if", "(", "isset", "(...
Generate URL for creating an object @return string
[ "Generate", "URL", "for", "creating", "an", "object" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L816-L837
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.isObjCreatable
public function isObjCreatable() { $model = $this->proto(); $method = [ $model, 'isCreatable' ]; if (is_callable($method)) { return call_user_func($method); } return true; }
php
public function isObjCreatable() { $model = $this->proto(); $method = [ $model, 'isCreatable' ]; if (is_callable($method)) { return call_user_func($method); } return true; }
[ "public", "function", "isObjCreatable", "(", ")", "{", "$", "model", "=", "$", "this", "->", "proto", "(", ")", ";", "$", "method", "=", "[", "$", "model", ",", "'isCreatable'", "]", ";", "if", "(", "is_callable", "(", "$", "method", ")", ")", "{",...
Determine if the object can be created. If TRUE, the "Create" button is shown. Objects can still be inserted programmatically or via direct action on the database. @return boolean
[ "Determine", "if", "the", "object", "can", "be", "created", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L847-L857
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.isObjEditable
public function isObjEditable() { $model = ($this->currentObj) ? $this->currentObj : $this->proto(); $method = [ $model, 'isEditable' ]; if (is_callable($method)) { return call_user_func($method); } return true; }
php
public function isObjEditable() { $model = ($this->currentObj) ? $this->currentObj : $this->proto(); $method = [ $model, 'isEditable' ]; if (is_callable($method)) { return call_user_func($method); } return true; }
[ "public", "function", "isObjEditable", "(", ")", "{", "$", "model", "=", "(", "$", "this", "->", "currentObj", ")", "?", "$", "this", "->", "currentObj", ":", "$", "this", "->", "proto", "(", ")", ";", "$", "method", "=", "[", "$", "model", ",", ...
Determine if the object can be modified. If TRUE, the "Modify" button is shown. Objects can still be updated programmatically or via direct action on the database. @return boolean
[ "Determine", "if", "the", "object", "can", "be", "modified", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L867-L877
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.createCollectionLoader
protected function createCollectionLoader() { $loader = $this->createCollectionLoaderFromTrait(); $mainMenu = filter_input(INPUT_GET, 'main_menu', FILTER_SANITIZE_STRING); if ($mainMenu) { $loader->setCallback(function (&$obj) use ($mainMenu) { if (!$obj['main_menu']) { $obj['main_menu'] = $mainMenu; } }); } return $loader; }
php
protected function createCollectionLoader() { $loader = $this->createCollectionLoaderFromTrait(); $mainMenu = filter_input(INPUT_GET, 'main_menu', FILTER_SANITIZE_STRING); if ($mainMenu) { $loader->setCallback(function (&$obj) use ($mainMenu) { if (!$obj['main_menu']) { $obj['main_menu'] = $mainMenu; } }); } return $loader; }
[ "protected", "function", "createCollectionLoader", "(", ")", "{", "$", "loader", "=", "$", "this", "->", "createCollectionLoaderFromTrait", "(", ")", ";", "$", "mainMenu", "=", "filter_input", "(", "INPUT_GET", ",", "'main_menu'", ",", "FILTER_SANITIZE_STRING", ")...
Create a collection loader. @return CollectionLoader
[ "Create", "a", "collection", "loader", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L945-L959
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.setListActions
protected function setListActions(array $actions) { $this->parsedListActions = false; $this->listActions = $this->mergeActions($this->defaultListActions(), $actions); return $this; }
php
protected function setListActions(array $actions) { $this->parsedListActions = false; $this->listActions = $this->mergeActions($this->defaultListActions(), $actions); return $this; }
[ "protected", "function", "setListActions", "(", "array", "$", "actions", ")", "{", "$", "this", "->", "parsedListActions", "=", "false", ";", "$", "this", "->", "listActions", "=", "$", "this", "->", "mergeActions", "(", "$", "this", "->", "defaultListAction...
Set the table's collection actions. @param array $actions One or more actions. @return TableWidget Chainable.
[ "Set", "the", "table", "s", "collection", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L1032-L1039
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.createListActions
protected function createListActions(array $actions) { $this->actionsPriority = $this->defaultActionPriority(); $listActions = $this->parseAsListActions($actions); return $listActions; }
php
protected function createListActions(array $actions) { $this->actionsPriority = $this->defaultActionPriority(); $listActions = $this->parseAsListActions($actions); return $listActions; }
[ "protected", "function", "createListActions", "(", "array", "$", "actions", ")", "{", "$", "this", "->", "actionsPriority", "=", "$", "this", "->", "defaultActionPriority", "(", ")", ";", "$", "listActions", "=", "$", "this", "->", "parseAsListActions", "(", ...
Build the table collection actions. List actions should come from the collection settings defined by the "collection_ident". It is still possible to completly override those externally by setting the "list_actions" with the {@see self::setListActions()} method. @param array $actions Actions to resolve. @return array List actions.
[ "Build", "the", "table", "collection", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L1051-L1058
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.parseAsListActions
protected function parseAsListActions(array $actions) { $listActions = []; foreach ($actions as $ident => $action) { $ident = $this->parseActionIdent($ident, $action); $action = $this->parseActionItem($action, $ident, true); if (!isset($action['priority'])) { $action['priority'] = $this->actionsPriority++; } if ($action['ident'] === 'create') { $action['empty'] = true; if (!$this->isObjCreatable()) { $action['active'] = false; } } else { $action['empty'] = (isset($action['empty']) ? boolval($action['empty']) : false); } if (is_array($action['actions'])) { $action['actions'] = $this->parseAsListActions($action['actions']); $action['hasActions'] = !!array_filter($action['actions'], function ($action) { return $action['active']; }); } if (isset($listActions[$ident])) { $hasPriority = ($action['priority'] > $listActions[$ident]['priority']); if ($hasPriority || $action['isSubmittable']) { $listActions[$ident] = array_replace($listActions[$ident], $action); } else { $listActions[$ident] = array_replace($action, $listActions[$ident]); } } else { $listActions[$ident] = $action; } } usort($listActions, [ $this, 'sortActionsByPriority' ]); while (($first = reset($listActions)) && $first['isSeparator']) { array_shift($listActions); } while (($last = end($listActions)) && $last['isSeparator']) { array_pop($listActions); } return $listActions; }
php
protected function parseAsListActions(array $actions) { $listActions = []; foreach ($actions as $ident => $action) { $ident = $this->parseActionIdent($ident, $action); $action = $this->parseActionItem($action, $ident, true); if (!isset($action['priority'])) { $action['priority'] = $this->actionsPriority++; } if ($action['ident'] === 'create') { $action['empty'] = true; if (!$this->isObjCreatable()) { $action['active'] = false; } } else { $action['empty'] = (isset($action['empty']) ? boolval($action['empty']) : false); } if (is_array($action['actions'])) { $action['actions'] = $this->parseAsListActions($action['actions']); $action['hasActions'] = !!array_filter($action['actions'], function ($action) { return $action['active']; }); } if (isset($listActions[$ident])) { $hasPriority = ($action['priority'] > $listActions[$ident]['priority']); if ($hasPriority || $action['isSubmittable']) { $listActions[$ident] = array_replace($listActions[$ident], $action); } else { $listActions[$ident] = array_replace($action, $listActions[$ident]); } } else { $listActions[$ident] = $action; } } usort($listActions, [ $this, 'sortActionsByPriority' ]); while (($first = reset($listActions)) && $first['isSeparator']) { array_shift($listActions); } while (($last = end($listActions)) && $last['isSeparator']) { array_pop($listActions); } return $listActions; }
[ "protected", "function", "parseAsListActions", "(", "array", "$", "actions", ")", "{", "$", "listActions", "=", "[", "]", ";", "foreach", "(", "$", "actions", "as", "$", "ident", "=>", "$", "action", ")", "{", "$", "ident", "=", "$", "this", "->", "p...
Parse the given actions as collection actions. @param array $actions Actions to resolve. @return array
[ "Parse", "the", "given", "actions", "as", "collection", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L1066-L1117
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.defaultObjectActions
protected function defaultObjectActions() { if ($this->defaultObjectActions === null) { $edit = [ 'label' => $this->translator()->translation('Modify'), 'url' => $this->objectEditUrl().'&obj_id={{id}}', 'ident' => 'edit', 'priority' => 1 ]; $this->defaultObjectActions = [ $edit ]; } return $this->defaultObjectActions; }
php
protected function defaultObjectActions() { if ($this->defaultObjectActions === null) { $edit = [ 'label' => $this->translator()->translation('Modify'), 'url' => $this->objectEditUrl().'&obj_id={{id}}', 'ident' => 'edit', 'priority' => 1 ]; $this->defaultObjectActions = [ $edit ]; } return $this->defaultObjectActions; }
[ "protected", "function", "defaultObjectActions", "(", ")", "{", "if", "(", "$", "this", "->", "defaultObjectActions", "===", "null", ")", "{", "$", "edit", "=", "[", "'label'", "=>", "$", "this", "->", "translator", "(", ")", "->", "translation", "(", "'...
Retrieve the table's default object actions. @return array
[ "Retrieve", "the", "table", "s", "default", "object", "actions", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L1138-L1151
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Widget/TableWidget.php
TableWidget.parsePropertyCellClasses
protected function parsePropertyCellClasses( PropertyInterface $property, ModelInterface $object = null ) { unset($object); $ident = $property->ident(); $classes = [ sprintf('property-%s', $ident) ]; $options = $this->viewOptions($ident); if (isset($options['classes'])) { if (is_array($options['classes'])) { $classes = array_merge($classes, $options['classes']); } else { $classes[] = $options['classes']; } } return $classes; }
php
protected function parsePropertyCellClasses( PropertyInterface $property, ModelInterface $object = null ) { unset($object); $ident = $property->ident(); $classes = [ sprintf('property-%s', $ident) ]; $options = $this->viewOptions($ident); if (isset($options['classes'])) { if (is_array($options['classes'])) { $classes = array_merge($classes, $options['classes']); } else { $classes[] = $options['classes']; } } return $classes; }
[ "protected", "function", "parsePropertyCellClasses", "(", "PropertyInterface", "$", "property", ",", "ModelInterface", "$", "object", "=", "null", ")", "{", "unset", "(", "$", "object", ")", ";", "$", "ident", "=", "$", "property", "->", "ident", "(", ")", ...
Filter the table cell's CSS classes before the property is assigned to the object row. This method is useful for classes using this trait. @param PropertyInterface $property The current property. @param ModelInterface|null $object Optional. The current row's object. @return array
[ "Filter", "the", "table", "cell", "s", "CSS", "classes", "before", "the", "property", "is", "assigned", "to", "the", "object", "row", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Widget/TableWidget.php#L1235-L1254
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/HttpAwareTrait.php
HttpAwareTrait.httpRequest
public function httpRequest() { if ($this->httpRequest === null) { throw new RuntimeException(sprintf( 'PSR-7 HTTP Request is not defined for "%s"', get_class($this) )); } return $this->httpRequest; }
php
public function httpRequest() { if ($this->httpRequest === null) { throw new RuntimeException(sprintf( 'PSR-7 HTTP Request is not defined for "%s"', get_class($this) )); } return $this->httpRequest; }
[ "public", "function", "httpRequest", "(", ")", "{", "if", "(", "$", "this", "->", "httpRequest", "===", "null", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'PSR-7 HTTP Request is not defined for \"%s\"'", ",", "get_class", "(", "$", "this...
Retrieve the HTTP request. @throws RuntimeException If the HTTP request was not previously set. @return RequestInterface
[ "Retrieve", "the", "HTTP", "request", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/HttpAwareTrait.php#L37-L47
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/HttpAwareTrait.php
HttpAwareTrait.httpResponse
public function httpResponse() { if ($this->httpResponse === null) { throw new RuntimeException(sprintf( 'PSR-7 HTTP Response is not defined for "%s"', get_class($this) )); } return $this->httpResponse; }
php
public function httpResponse() { if ($this->httpResponse === null) { throw new RuntimeException(sprintf( 'PSR-7 HTTP Response is not defined for "%s"', get_class($this) )); } return $this->httpResponse; }
[ "public", "function", "httpResponse", "(", ")", "{", "if", "(", "$", "this", "->", "httpResponse", "===", "null", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'PSR-7 HTTP Response is not defined for \"%s\"'", ",", "get_class", "(", "$", "t...
Retrieve the HTTP response. @throws RuntimeException If the HTTP response was not previously set. @return ResponseInterface
[ "Retrieve", "the", "HTTP", "response", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/HttpAwareTrait.php#L76-L86
train
acquia/commerce-manager
modules/acm/src/DatabaseSessionStore.php
DatabaseSessionStore.setOwnerReference
protected function setOwnerReference($uid, $owner_id) { $key = $uid . ':' . self::OWNER_REFERENCE_NAMESPACE; if (!$this->lockBackend->acquire($key)) { $this->lockBackend->wait($key); if (!$this->lockBackend->acquire($key)) { throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage."); } } $value = (object) [ 'owner' => $uid, 'data' => $owner_id, 'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'), ]; $this->storage->setWithExpire($key, $value, $this->expire); $this->lockBackend->release($key); }
php
protected function setOwnerReference($uid, $owner_id) { $key = $uid . ':' . self::OWNER_REFERENCE_NAMESPACE; if (!$this->lockBackend->acquire($key)) { $this->lockBackend->wait($key); if (!$this->lockBackend->acquire($key)) { throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage."); } } $value = (object) [ 'owner' => $uid, 'data' => $owner_id, 'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'), ]; $this->storage->setWithExpire($key, $value, $this->expire); $this->lockBackend->release($key); }
[ "protected", "function", "setOwnerReference", "(", "$", "uid", ",", "$", "owner_id", ")", "{", "$", "key", "=", "$", "uid", ".", "':'", ".", "self", "::", "OWNER_REFERENCE_NAMESPACE", ";", "if", "(", "!", "$", "this", "->", "lockBackend", "->", "acquire"...
Stores a reference to the current store owner for a particular user. @param string $uid The user id to relate to the current store. @param string $owner_id The store owner to associate this user to. @throws \Drupal\Core\TempStore\TempStoreException Thrown when a lock for the backend storage could not be acquired.
[ "Stores", "a", "reference", "to", "the", "current", "store", "owner", "for", "a", "particular", "user", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/DatabaseSessionStore.php#L127-L143
train
acquia/commerce-manager
modules/acm/src/DatabaseSessionStore.php
DatabaseSessionStore.getOwnerReference
protected function getOwnerReference($uid) { $key = $uid . ':' . self::OWNER_REFERENCE_NAMESPACE; if (($object = $this->storage->get($key)) && ($object->owner == $uid)) { return $object->data; } }
php
protected function getOwnerReference($uid) { $key = $uid . ':' . self::OWNER_REFERENCE_NAMESPACE; if (($object = $this->storage->get($key)) && ($object->owner == $uid)) { return $object->data; } }
[ "protected", "function", "getOwnerReference", "(", "$", "uid", ")", "{", "$", "key", "=", "$", "uid", ".", "':'", ".", "self", "::", "OWNER_REFERENCE_NAMESPACE", ";", "if", "(", "(", "$", "object", "=", "$", "this", "->", "storage", "->", "get", "(", ...
Gets the reference to the current store owner for a particular user. @param string $uid The user id to relate to the current store. @throws \Drupal\Core\TempStore\TempStoreException Thrown when a lock for the backend storage could not be acquired.
[ "Gets", "the", "reference", "to", "the", "current", "store", "owner", "for", "a", "particular", "user", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm/src/DatabaseSessionStore.php#L154-L159
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Action/Object/LoadAction.php
LoadAction.loadObjectCollection
protected function loadObjectCollection($objType) { $proto = $this->modelFactory()->get($objType); $loader = $this->collectionLoader(); $loader->setModel($proto); $loader->addFilter('active', true); $this->objCollection = $loader->load(); return $this->objCollection; }
php
protected function loadObjectCollection($objType) { $proto = $this->modelFactory()->get($objType); $loader = $this->collectionLoader(); $loader->setModel($proto); $loader->addFilter('active', true); $this->objCollection = $loader->load(); return $this->objCollection; }
[ "protected", "function", "loadObjectCollection", "(", "$", "objType", ")", "{", "$", "proto", "=", "$", "this", "->", "modelFactory", "(", ")", "->", "get", "(", "$", "objType", ")", ";", "$", "loader", "=", "$", "this", "->", "collectionLoader", "(", ...
Load Object Collection @param string $objType The object type as string. @return \Charcoal\Model\Collection
[ "Load", "Object", "Collection" ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Action/Object/LoadAction.php#L245-L255
train
acquia/commerce-manager
modules/acm_sku/src/Controller/SKUController.php
SKUController.add
public function add(SKUTypeInterface $acm_sku_type) { $sku = $this->entityManager() ->getStorage('acm_sku') ->create(['type' => $acm_sku_type->id()]); $form = $this->entityFormBuilder()->getForm($sku); return $form; }
php
public function add(SKUTypeInterface $acm_sku_type) { $sku = $this->entityManager() ->getStorage('acm_sku') ->create(['type' => $acm_sku_type->id()]); $form = $this->entityFormBuilder()->getForm($sku); return $form; }
[ "public", "function", "add", "(", "SKUTypeInterface", "$", "acm_sku_type", ")", "{", "$", "sku", "=", "$", "this", "->", "entityManager", "(", ")", "->", "getStorage", "(", "'acm_sku'", ")", "->", "create", "(", "[", "'type'", "=>", "$", "acm_sku_type", ...
Provides the SKU submission form. @param \Drupal\acm_sku\Entity\SKUTypeInterface $acm_sku_type The SKU type entity for the SKU. @return array A SKU submission form.
[ "Provides", "the", "SKU", "submission", "form", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Controller/SKUController.php#L24-L32
train
acquia/commerce-manager
modules/acm_sku/src/Controller/SKUController.php
SKUController.addPage
public function addPage() { $build = [ '#theme' => 'sku_add_list', '#cache' => [ 'tags' => $this->entityManager()->getDefinition('acm_sku_type')->getListCacheTags(), ], ]; $content = []; foreach ($this->entityManager()->getStorage('acm_sku_type')->loadMultiple() as $type) { $content[$type->id()] = $type; } // Bypass the sku/add listing if only one content type is available. if (count($content) == 1) { $type = array_shift($content); return $this->redirect('acm_sku.sku_add', ['acm_sku_type' => $type->id()]); } $build['#content'] = $content; return $build; }
php
public function addPage() { $build = [ '#theme' => 'sku_add_list', '#cache' => [ 'tags' => $this->entityManager()->getDefinition('acm_sku_type')->getListCacheTags(), ], ]; $content = []; foreach ($this->entityManager()->getStorage('acm_sku_type')->loadMultiple() as $type) { $content[$type->id()] = $type; } // Bypass the sku/add listing if only one content type is available. if (count($content) == 1) { $type = array_shift($content); return $this->redirect('acm_sku.sku_add', ['acm_sku_type' => $type->id()]); } $build['#content'] = $content; return $build; }
[ "public", "function", "addPage", "(", ")", "{", "$", "build", "=", "[", "'#theme'", "=>", "'sku_add_list'", ",", "'#cache'", "=>", "[", "'tags'", "=>", "$", "this", "->", "entityManager", "(", ")", "->", "getDefinition", "(", "'acm_sku_type'", ")", "->", ...
Displays add SKU links for available SKU types. Redirects to /admin/commerce/sku/add/[type] if only one content type is available. @return array|\Symfony\Component\HttpFoundation\RedirectResponse A render array for a list of the SKU types that can be added; however, if there is only one SKU type defined for the site, the function will return a RedirectResponse to the SKU add page for that one SKU type.
[ "Displays", "add", "SKU", "links", "for", "available", "SKU", "types", "." ]
e6c3a5fb9166d6c447725339ac4e0ae341c06d50
https://github.com/acquia/commerce-manager/blob/e6c3a5fb9166d6c447725339ac4e0ae341c06d50/modules/acm_sku/src/Controller/SKUController.php#L59-L82
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/AdminTrait.php
AdminTrait.adminConfig
protected function adminConfig($key = null, $default = null) { if ($key) { if (isset($this->adminConfig[$key])) { return $this->adminConfig[$key]; } else { if (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } } } return $this->adminConfig; }
php
protected function adminConfig($key = null, $default = null) { if ($key) { if (isset($this->adminConfig[$key])) { return $this->adminConfig[$key]; } else { if (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } } } return $this->adminConfig; }
[ "protected", "function", "adminConfig", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "adminConfig", "[", "$", "key", "]", ")", ")", "{", "...
Retrieve the admin's configset. @param string|null $key Optional data key to retrieve from the configset. @param mixed|null $default The default value to return if data key does not exist. @return mixed|AdminConfig
[ "Retrieve", "the", "admin", "s", "configset", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/AdminTrait.php#L76-L91
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/AdminTrait.php
AdminTrait.appConfig
protected function appConfig($key = null, $default = null) { if ($key) { if (isset($this->appConfig[$key])) { return $this->appConfig[$key]; } else { if (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } } } return $this->appConfig; }
php
protected function appConfig($key = null, $default = null) { if ($key) { if (isset($this->appConfig[$key])) { return $this->appConfig[$key]; } else { if (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } } } return $this->appConfig; }
[ "protected", "function", "appConfig", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "appConfig", "[", "$", "key", "]", ")", ")", "{", "retu...
Retrieve the application's configset. @param string|null $key Optional data key to retrieve from the configset. @param mixed|null $default The default value to return if data key does not exist. @return mixed|AppConfig
[ "Retrieve", "the", "application", "s", "configset", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/AdminTrait.php#L111-L126
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Support/AdminTrait.php
AdminTrait.apiConfig
protected function apiConfig($key, $default = null) { $key = 'apis.'.$key; if (isset($this->adminConfig[$key])) { return $this->adminConfig[$key]; } elseif (isset($this->appConfig[$key])) { return $this->appConfig[$key]; } elseif (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } }
php
protected function apiConfig($key, $default = null) { $key = 'apis.'.$key; if (isset($this->adminConfig[$key])) { return $this->adminConfig[$key]; } elseif (isset($this->appConfig[$key])) { return $this->appConfig[$key]; } elseif (!is_string($default) && is_callable($default)) { return $default(); } else { return $default; } }
[ "protected", "function", "apiConfig", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "$", "key", "=", "'apis.'", ".", "$", "key", ";", "if", "(", "isset", "(", "$", "this", "->", "adminConfig", "[", "$", "key", "]", ")", ")", "{", ...
Retrieve a value from the API configset. Looks up the admin module first, the application second. @param string|null $key Optional data key to retrieve from the configset. @param mixed|null $default The default value to return if data key does not exist. @return mixed
[ "Retrieve", "a", "value", "from", "the", "API", "configset", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Support/AdminTrait.php#L137-L150
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Property/Input/SelectizeInput.php
SelectizeInput.setData
public function setData(array $data) { // Push selectize options back at the end of the data container. if (isset($data['selectizeOptions'])) { $selectizeOptions = $data['selectizeOptions']; unset($data['selectizeOptions']); $data['selectizeOptions'] = $selectizeOptions; } parent::setData($data); return $this; }
php
public function setData(array $data) { // Push selectize options back at the end of the data container. if (isset($data['selectizeOptions'])) { $selectizeOptions = $data['selectizeOptions']; unset($data['selectizeOptions']); $data['selectizeOptions'] = $selectizeOptions; } parent::setData($data); return $this; }
[ "public", "function", "setData", "(", "array", "$", "data", ")", "{", "// Push selectize options back at the end of the data container.", "if", "(", "isset", "(", "$", "data", "[", "'selectizeOptions'", "]", ")", ")", "{", "$", "selectizeOptions", "=", "$", "data"...
This function takes an array and fill the model object with its value. This method either calls a setter for each key (`set_{$key}()`) or sets a public member. For example, calling with `setData(['properties'=>$properties])` would call `setProperties($properties)`, becasue `setProperties()` exists. But calling with `setData(['foobar'=>$foo])` would set the `$foobar` member on the metadata object, because the method `set_foobar()` does not exist. @param array $data The input data. @return self
[ "This", "function", "takes", "an", "array", "and", "fill", "the", "model", "object", "with", "its", "value", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Property/Input/SelectizeInput.php#L141-L153
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.setDataFromRequest
protected function setDataFromRequest(RequestInterface $request) { $keys = $this->validDataFromRequest(); $data = $request->getParams($keys); if (isset($data['obj_type'])) { $this->objType = filter_var($data['obj_type'], FILTER_SANITIZE_STRING); } if (isset($data['obj_id'])) { $this->objId = filter_var($data['obj_id'], FILTER_SANITIZE_STRING); } if (isset($data['property'])) { $this->propertyIdent = filter_var($data['property'], FILTER_SANITIZE_STRING); } if (isset($data['assets'])) { $this->showAssets = !!$data['assets']; } if (isset($data['callback'])) { $this->callbackIdent = filter_var($data['callback'], FILTER_SANITIZE_STRING); } if (isset($this->elfinderConfig['translations'])) { $this->setLocalizations(array_replace_recursive( $this->defaultLocalizations(), $this->elfinderConfig['translations'] )); } return true; }
php
protected function setDataFromRequest(RequestInterface $request) { $keys = $this->validDataFromRequest(); $data = $request->getParams($keys); if (isset($data['obj_type'])) { $this->objType = filter_var($data['obj_type'], FILTER_SANITIZE_STRING); } if (isset($data['obj_id'])) { $this->objId = filter_var($data['obj_id'], FILTER_SANITIZE_STRING); } if (isset($data['property'])) { $this->propertyIdent = filter_var($data['property'], FILTER_SANITIZE_STRING); } if (isset($data['assets'])) { $this->showAssets = !!$data['assets']; } if (isset($data['callback'])) { $this->callbackIdent = filter_var($data['callback'], FILTER_SANITIZE_STRING); } if (isset($this->elfinderConfig['translations'])) { $this->setLocalizations(array_replace_recursive( $this->defaultLocalizations(), $this->elfinderConfig['translations'] )); } return true; }
[ "protected", "function", "setDataFromRequest", "(", "RequestInterface", "$", "request", ")", "{", "$", "keys", "=", "$", "this", "->", "validDataFromRequest", "(", ")", ";", "$", "data", "=", "$", "request", "->", "getParams", "(", "$", "keys", ")", ";", ...
Sets the template data from a PSR Request object. @param RequestInterface $request A PSR-7 compatible Request instance. @return self
[ "Sets", "the", "template", "data", "from", "a", "PSR", "Request", "object", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L95-L128
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.setLocalizations
public function setLocalizations(array $localizations) { $this->localizations = new ArrayIterator(); foreach ($localizations as $ident => $translations) { $this->addLocalization($ident, $translations); } return $this; }
php
public function setLocalizations(array $localizations) { $this->localizations = new ArrayIterator(); foreach ($localizations as $ident => $translations) { $this->addLocalization($ident, $translations); } return $this; }
[ "public", "function", "setLocalizations", "(", "array", "$", "localizations", ")", "{", "$", "this", "->", "localizations", "=", "new", "ArrayIterator", "(", ")", ";", "foreach", "(", "$", "localizations", "as", "$", "ident", "=>", "$", "translations", ")", ...
Set the custom localization messages. @param array $localizations An associative array of localizations. @return self
[ "Set", "the", "custom", "localization", "messages", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L165-L174
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.addLocalization
public function addLocalization($ident, $translations) { if (!is_string($ident)) { throw new InvalidArgumentException(sprintf( 'Translation key must be a string, received %s', (is_object($ident) ? get_class($ident) : gettype($ident)) )); } $this->localizations[$ident] = $this->translator()->translation($translations); return $this; }
php
public function addLocalization($ident, $translations) { if (!is_string($ident)) { throw new InvalidArgumentException(sprintf( 'Translation key must be a string, received %s', (is_object($ident) ? get_class($ident) : gettype($ident)) )); } $this->localizations[$ident] = $this->translator()->translation($translations); return $this; }
[ "public", "function", "addLocalization", "(", "$", "ident", ",", "$", "translations", ")", "{", "if", "(", "!", "is_string", "(", "$", "ident", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Translation key must be a string, re...
Add a custom localization message. @param string $ident The message ID. @param mixed $translations The message translations. @throws InvalidArgumentException If the message ID is not a string or the translations are invalid. @return self
[ "Add", "a", "custom", "localization", "message", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L184-L196
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.removeLocalization
public function removeLocalization($ident) { if (!is_string($ident)) { throw new InvalidArgumentException(sprintf( 'Translation key must be a string, received %s', (is_object($ident) ? get_class($ident) : gettype($ident)) )); } unset($this->localizations[$ident]); return $this; }
php
public function removeLocalization($ident) { if (!is_string($ident)) { throw new InvalidArgumentException(sprintf( 'Translation key must be a string, received %s', (is_object($ident) ? get_class($ident) : gettype($ident)) )); } unset($this->localizations[$ident]); return $this; }
[ "public", "function", "removeLocalization", "(", "$", "ident", ")", "{", "if", "(", "!", "is_string", "(", "$", "ident", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Translation key must be a string, received %s'", ",", "(", ...
Remove the translations for the given message ID. @param string $ident The message ID to remove. @throws InvalidArgumentException If the message ID is not a string. @return self
[ "Remove", "the", "translations", "for", "the", "given", "message", "ID", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L205-L217
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.localizations
public function localizations() { if ($this->localizations === null) { $this->setLocalizations($this->defaultLocalizations()); } return $this->localizations; }
php
public function localizations() { if ($this->localizations === null) { $this->setLocalizations($this->defaultLocalizations()); } return $this->localizations; }
[ "public", "function", "localizations", "(", ")", "{", "if", "(", "$", "this", "->", "localizations", "===", "null", ")", "{", "$", "this", "->", "setLocalizations", "(", "$", "this", "->", "defaultLocalizations", "(", ")", ")", ";", "}", "return", "$", ...
Retrieve the localizations. @return {\Charcoal\Translator\Translation|string}[]|null
[ "Retrieve", "the", "localizations", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L244-L251
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.localization
public function localization($ident) { if (!is_string($ident)) { throw new InvalidArgumentException(sprintf( 'Translation key must be a string, received %s', (is_object($ident) ? get_class($ident) : gettype($ident)) )); } if (isset($this->localizations[$ident])) { return $this->localizations[$ident]; } return $ident; }
php
public function localization($ident) { if (!is_string($ident)) { throw new InvalidArgumentException(sprintf( 'Translation key must be a string, received %s', (is_object($ident) ? get_class($ident) : gettype($ident)) )); } if (isset($this->localizations[$ident])) { return $this->localizations[$ident]; } return $ident; }
[ "public", "function", "localization", "(", "$", "ident", ")", "{", "if", "(", "!", "is_string", "(", "$", "ident", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Translation key must be a string, received %s'", ",", "(", "is_ob...
Retrieve the translations for the given message ID. @param string $ident The message ID to lookup. @throws InvalidArgumentException If the message ID is not a string. @return \Charcoal\Translator\Translation|string|null
[ "Retrieve", "the", "translations", "for", "the", "given", "message", "ID", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L260-L274
train
locomotivemtl/charcoal-admin
src/Charcoal/Admin/Template/ElfinderTemplate.php
ElfinderTemplate.elfinderLocalizationsAsJson
public function elfinderLocalizationsAsJson() { $i18n = []; foreach ($this->localizations() as $id => $translations) { foreach ($translations->data() as $language => $message) { $i18n[$language][$id] = $message; } } return json_encode($i18n, (JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE)); }
php
public function elfinderLocalizationsAsJson() { $i18n = []; foreach ($this->localizations() as $id => $translations) { foreach ($translations->data() as $language => $message) { $i18n[$language][$id] = $message; } } return json_encode($i18n, (JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE)); }
[ "public", "function", "elfinderLocalizationsAsJson", "(", ")", "{", "$", "i18n", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "localizations", "(", ")", "as", "$", "id", "=>", "$", "translations", ")", "{", "foreach", "(", "$", "translations", ...
Retrieve the custom localizations for elFinder. @return string Returns data serialized with {@see json_encode()}.
[ "Retrieve", "the", "custom", "localizations", "for", "elFinder", "." ]
d7394e62ab8b374bcdd1dbeaedec0f6c35624571
https://github.com/locomotivemtl/charcoal-admin/blob/d7394e62ab8b374bcdd1dbeaedec0f6c35624571/src/Charcoal/Admin/Template/ElfinderTemplate.php#L281-L292
train