commerce-8.x-2.8/modules/store/commerce_store.module

modules/store/commerce_store.module
<?php

/**
 * @file
 * Defines the Store entity and associated features.
 */

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;

/**
 * Implements hook_theme().
 */
function commerce_store_theme() {
  return [
    'commerce_store' => [
      'render element' => 'elements',
    ],
  ];
}

/**
 * Implements hook_field_widget_form_alter().
 */
function commerce_store_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
  /** @var \Drupal\Core\Field\BaseFieldDefinition $field_definition */
  $field_definition = $context['items']->getFieldDefinition();
  $field_name = $field_definition->getName();
  $entity_type = $field_definition->getTargetEntityTypeId();
  $widget_name = $context['widget']->getPluginId();
  if ($field_name == 'billing_countries' && $entity_type == 'commerce_store' && $widget_name == 'options_select') {
    $element['#options']['_none'] = t('- All countries -');
    $element['#size'] = 5;
  }
}

/**
 * Implements hook_theme_suggestions_commerce_store().
 */
function commerce_store_theme_suggestions_commerce_store(array $variables) {
  return _commerce_entity_theme_suggestions('commerce_store', $variables);
}

/**
 * Prepares variables for store templates.
 *
 * Default template: commerce-store.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An associative array containing rendered fields.
 *   - attributes: HTML attributes for the containing element.
 */
function template_preprocess_commerce_store(array &$variables) {
  /** @var Drupal\commerce_store\Entity\StoreInterface $store */
  $store = $variables['elements']['#commerce_store'];

  $variables['store_entity'] = $store;
  $variables['store_url'] = $store->isNew() ? '' : $store->toUrl();
  $variables['store'] = [];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['store'][$key] = $variables['elements'][$key];
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc