Skip to content
Snippets Groups Projects

Restrict buttons to node forms

1 file
+ 3
4
Compare changes
  • Side-by-side
  • Inline
@@ -8,20 +8,19 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\openai\Utility\StringHelper;
/**
* Implements hook_form_alter().
* Implements hook_form_node_form_alter().
*/
function openai_content_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
function openai_content_form_node_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
$account = \Drupal::currentUser();
$form_object = $form_state->getFormObject();
if ($form_object instanceof ContentEntityFormInterface && $account->hasPermission('access openai content tools')) {
if ($account->hasPermission('access openai content tools')) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $form_object->getEntity();
$options = _get_all_text_with_summary_fields($entity);
Loading