You are here

function commerce_wishlist_field_formatter_third_party_settings_form in Commerce Wishlist 8.3

Implements hook_field_formatter_third_party_settings_form().

Extends the add to cart formatter form with a show wishlist button.

File

./commerce_wishlist.module, line 173
Defines the Wishlist entity and associated features.

Code

function commerce_wishlist_field_formatter_third_party_settings_form(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state) {
  $element = [];
  if ($plugin
    ->getPluginId() == 'commerce_add_to_cart') {
    $element['show_wishlist'] = [
      '#type' => 'checkbox',
      '#title' => t('Show wishlist button'),
      '#default_value' => $plugin
        ->getThirdPartySetting('commerce_wishlist', 'show_wishlist', TRUE),
    ];
    $element['weight_wishlist'] = [
      '#type' => 'number',
      '#title' => t('Change the weight of the wishlist button.'),
      '#default_value' => $plugin
        ->getThirdPartySetting('commerce_wishlist', 'weight_wishlist', 99),
    ];
    $element['label_wishlist'] = [
      '#type' => 'textfield',
      '#title' => t('Override the wishlist button label'),
      '#default_value' => $plugin
        ->getThirdPartySetting('commerce_wishlist', 'label_wishlist'),
    ];
  }
  return $element;
}