You are here

public static function Utility::getFieldsConfig in Basic cart 8.5

Same name and namespace in other branches
  1. 8.6 src/Utility.php \Drupal\basic_cart\Utility::getFieldsConfig()
  2. 8 src/Utility.php \Drupal\basic_cart\Utility::getFieldsConfig()
  3. 8.0 src/Utility.php \Drupal\basic_cart\Utility::getFieldsConfig()
  4. 8.2 src/Utility.php \Drupal\basic_cart\Utility::getFieldsConfig()
  5. 8.3 src/Utility.php \Drupal\basic_cart\Utility::getFieldsConfig()
  6. 8.4 src/Utility.php \Drupal\basic_cart\Utility::getFieldsConfig()

Returns the fields we need to create.

Parameters

string $type: Type of field sets to be created.

Return value

mixed Key / Value pair of field name => field type.

1 call to Utility::getFieldsConfig()
Utility::createFields in src/Utility.php
Create Fields for content type basic cart enabled.

File

src/Utility.php, line 119

Class

Utility
Utilty functions for basic cart.

Namespace

Drupal\basic_cart

Code

public static function getFieldsConfig($type = NULL) {
  $config = self::cartSettings();
  $fields['bundle_types'] = $config
    ->get('content_type');
  foreach ($config
    ->get('content_type') as $key => $value) {
    if ($value) {
      $bundles[$key] = $key;
    }
  }
  $fields['bundle_types'] = $bundles;
  if ($type == self::FIELD_ORDERCONNECT) {
    $fields['bundle_types'] = array(
      'basic_cart_order' => 'basic_cart_order',
    );
    $fields['fields'] = array(
      'basic_cart_content' => array(
        'type' => 'entity_reference',
        'entity_type' => 'node',
        'bundle' => 'basic_cart_order',
        'title' => t('Basic cart content'),
        'label' => t('Basic cart content'),
        'required' => FALSE,
        'description' => t('Basic cart reference content'),
        'cardinality' => -1,
        'formatter' => array(
          'default' => array(
            'label' => 'inline',
            'type' => 'entity_reference_entity_view',
            'settings' => [
              'view_mode' => 'basic_cart_order',
            ],
          ),
          'search_result' => 'default',
          'teaser' => 'default',
        ),
        'widget' => array(
          'type' => 'entity_reference_autocomplete',
          'cardinality' => -1,
        ),
        'settings' => array(
          'handler' => 'default:node',
          'handler_settings' => array(
            "target_bundles" => $bundles,
          ),
        ),
      ),
    );
  }
  else {
    $fields['fields'] = array(
      'add_to_cart_price' => array(
        'type' => 'decimal',
        'entity_type' => 'node',
        'title' => t($config
          ->get('price_label')),
        'label' => t($config
          ->get('price_label')),
        'required' => FALSE,
        'description' => t("Please enter this item's price."),
        'cardinality' => 1,
        'widget' => array(
          'type' => 'number',
        ),
        'formatter' => array(
          'default' => array(
            'label' => 'inline',
            'type' => 'number_decimal',
            'weight' => 11,
          ),
          'search_result' => 'default',
          'teaser' => 'default',
        ),
      ),
      'add_to_cart' => array(
        'type' => 'addtocart',
        'entity_type' => 'node',
        'title' => t($config
          ->get('add_to_cart_button')),
        'label' => t($config
          ->get('add_to_cart_button')),
        'required' => FALSE,
        'description' => 'Enable add to cart button',
        'cardinality' => 1,
        'widget' => array(
          'type' => 'addtocart',
        ),
        'formatter' => array(
          'default' => array(
            'label' => 'hidden',
            'weight' => 11,
            'type' => $config
              ->get('quantity_status') ? 'addtocartwithquantity' : 'addtocart',
          ),
          'search_result' => array(
            'label' => 'hidden',
            'weight' => 11,
            'type' => 'addtocart',
          ),
          'teaser' => array(
            'label' => 'hidden',
            'weight' => 11,
            'type' => 'addtocart',
          ),
        ),
      ),
    );
  }
  return (object) $fields;
}