Skip to content
Snippets Groups Projects
Commit d120c08e authored by Kevin Quillen's avatar Kevin Quillen
Browse files

Merge branch '3364439-openai-content--' into '1.0.x'

Issue #3364439: OpenAI Content - only show fields that are present in the form

See merge request !44
parents d8b364d5 168b029e
No related branches found
No related tags found
No related merge requests found
Pipeline #11842 skipped
...@@ -11,9 +11,7 @@ use Drupal\Core\Ajax\HtmlCommand; ...@@ -11,9 +11,7 @@ use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\NodeForm;
use Drupal\openai\Utility\StringHelper; use Drupal\openai\Utility\StringHelper;
/** /**
...@@ -27,6 +25,7 @@ function openai_content_form_alter(array &$form, FormStateInterface $form_state, ...@@ -27,6 +25,7 @@ function openai_content_form_alter(array &$form, FormStateInterface $form_state,
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $form_object->getEntity(); $entity = $form_object->getEntity();
$options = _get_all_text_with_summary_fields($entity); $options = _get_all_text_with_summary_fields($entity);
$options = array_intersect_key($options, $form);
$form['openai_moderate'] = [ $form['openai_moderate'] = [
'#type' => 'details', '#type' => 'details',
...@@ -186,6 +185,11 @@ function _get_all_text_with_summary_fields(ContentEntityInterface $entity) { ...@@ -186,6 +185,11 @@ function _get_all_text_with_summary_fields(ContentEntityInterface $entity) {
foreach ($fields as $field) { foreach ($fields as $field) {
if (in_array($field->getType(), ['text_with_summary', 'text_long', 'string', 'string_long'])) { if (in_array($field->getType(), ['text_with_summary', 'text_long', 'string', 'string_long'])) {
// @todo: How to skip special fields?
if (in_array($field->getName(), ['revision_log', 'revision_log_message'])) {
continue;
}
$label = $field->getLabel(); $label = $field->getLabel();
if ($label instanceof TranslatableMarkup) { if ($label instanceof TranslatableMarkup) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment