You are here

public static function UsageLimitFormatter::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/promotion/src/Plugin/Field/FieldFormatter/UsageLimitFormatter.php, line 72

Class

UsageLimitFormatter
Plugin implementation of the 'commerce_usage_limit' formatter.

Namespace

Drupal\commerce_promotion\Plugin\Field\FieldFormatter

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {
  $entity_type = $field_definition
    ->getTargetEntityTypeId();
  $field_name = $field_definition
    ->getName();
  $applicable_entity_type = in_array($entity_type, [
    'commerce_promotion',
    'commerce_promotion_coupon',
  ]);
  $applicable_field_name = in_array($field_name, [
    'usage_limit',
    'usage_limit_customer',
  ]);
  return $applicable_entity_type && $applicable_field_name;
}