function commerce_add_to_wishlist_link_entity_extra_field_info in Commerce Add To Cart Link 8
Same name and namespace in other branches
- 2.x modules/wishlist/commerce_add_to_wishlist_link.module \commerce_add_to_wishlist_link_entity_extra_field_info()
Implements hook_entity_extra_field_info().
File
- modules/
wishlist/ commerce_add_to_wishlist_link.module, line 17 - Hook implementations of commerce_add_to_wishlist_link module.
Code
function commerce_add_to_wishlist_link_entity_extra_field_info() {
$fields = [];
// First, add a pseudo field to product variations.
/** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $product_variation_type */
foreach (ProductVariationType::loadMultiple() as $product_variation_type) {
$fields['commerce_product_variation'][$product_variation_type
->id()]['display']['add_to_wishlist_link'] = [
'label' => t('Add to wishlist link'),
'description' => t('Displays an add to wishlist link.'),
'weight' => 99,
// We hide the field by default, as there are in many cases more view
// modes to hide than to show (e.g. "cart", "summary").
'visible' => FALSE,
];
}
// For simplicity, add a field to products too (targeting default variation).
/** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */
foreach (ProductType::loadMultiple() as $product_type) {
$fields['commerce_product'][$product_type
->id()]['display']['add_to_wishlist_link'] = [
'label' => t('Add to wishlist link'),
'description' => t('Displays an add to wishlist link for the default variation of the product.'),
'weight' => 99,
// We hide the field by default.
'visible' => FALSE,
];
}
return $fields;
}