Skip to content

Instantly share code, notes, and snippets.

@aklump
Created March 29, 2024 21:46
Show Gist options
  • Save aklump/e715b12aa2a64f83efc0150373379238 to your computer and use it in GitHub Desktop.
Save aklump/e715b12aa2a64f83efc0150373379238 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\se_core\Traits;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
trait GetFormModeTrait {
protected function getFormMode(FormStateInterface $form_state): string {
$form_display = $form_state->getStorage()['form_display'];
if ($form_display instanceof EntityFormDisplay) {
return $form_display->get('mode');
}
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment