public static function AddToCartFormatter::isApplicable in Commerce Core 8.2
Returns if the formatter can be used for the provided field.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition that should be checked.
Return value
bool TRUE if the formatter can be used, FALSE otherwise.
Overrides FormatterBase::isApplicable
File
- modules/
product/ src/ Plugin/ Field/ FieldFormatter/ AddToCartFormatter.php, line 106
Class
- AddToCartFormatter
- Plugin implementation of the 'commerce_add_to_cart' formatter.
Namespace
Drupal\commerce_product\Plugin\Field\FieldFormatterCode
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$has_cart = \Drupal::moduleHandler()
->moduleExists('commerce_cart');
$entity_type = $field_definition
->getTargetEntityTypeId();
$field_name = $field_definition
->getName();
return $has_cart && $entity_type == 'commerce_product' && $field_name == 'variations';
}