You are here

public function PageExposure::applies in Flexiform 8

Whether this enhancer applies to a particular event.

Parameters

string $event: The enhancer event name.

Return value

bool True if the enhancer applies to a particular event.

Overrides ConfigurableFormEnhancerBase::applies

File

src/Plugin/FormEnhancer/PageExposure.php, line 144

Class

PageExposure
Plugin for exposing custom form modes on pages.

Namespace

Drupal\flexiform\Plugin\FormEnhancer

Code

public function applies($event) {

  // Only applies on custom form modes.
  if (!in_array($event, [
    'configuration_form',
    'init_form_entity_config',
  ])) {
    return FALSE;
  }
  else {
    $target_entity_type = $this
      ->getFormDisplay()
      ->getTargetEntityTypeId();
    $mode = $this
      ->getFormDisplay()
      ->getMode();
    if (!$target_entity_type || !$mode) {
      return FALSE;
    }

    // If we can load a custom form mode entity for this form display
    // than this enhancer applies.
    if ($this
      ->entityFormModeStorage()
      ->load("{$target_entity_type}.{$mode}")) {
      return 100;
    }
  }
  return FALSE;
}