You are here

public static function VariationAddToCartFormatter::isApplicable in Commerce Variation Add to Cart 8

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

src/Plugin/Field/FieldFormatter/VariationAddToCartFormatter.php, line 229

Class

VariationAddToCartFormatter
Plugin implementation of the 'variation_add_to_cart_form' formatter.

Namespace

Drupal\commerce_variation_add_to_cart\Plugin\Field\FieldFormatter

Code

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';
}