deepseek-1.x-dev/src/Plugin/Action/AiUserEmbedding.php
src/Plugin/Action/AiUserEmbedding.php
<?php
namespace Drupal\deepseek\Plugin\Action;
use Drupal\Core\Action\Attribute\Action;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Provides an AI Embedding action.
*
* @DCG
* For updating entity fields consider extending FieldUpdateActionBase.
* @see \Drupal\Core\Field\FieldUpdateActionBase
*
* @DCG
* In order to set up the action through admin interface the plugin has to be
* configurable.
* @see https://www.drupal.org/project/drupal/issues/2815301
* @see https://www.drupal.org/project/drupal/issues/2815297
*
* @DCG
* The whole action API is subject of change.
* @see https://www.drupal.org/project/drupal/issues/2011038
*/
#[Action(
id: 'ai_user_embedding',
label: new TranslatableMarkup('AI Embedding'),
category: new TranslatableMarkup('AI'),
type: 'user',
)]
class AiUserEmbedding extends AiNodeEmbedding {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$entity_type = 'user';
$form['view_mode'] = [
'#type' => 'select',
'#title' => $this->t('Select the views mode, it will render the content to be embedding'),
'#default_value' => $this->configuration['view_mode'],
'#options' => $this->getViewModeList($entity_type),
];
$form['skip_indexed'] = [
'#type' => 'checkbox',
'#title' => $this->t('Skip indexed elements'),
'#default_value' => $this->configuration['skip_indexed'],
];
$isEmbedding = $this->aiSettings->get('embedding');
if (empty($isEmbedding)) {
$form["actions"]['submit']['#access'] = FALSE;
$this->messenger()->addError($this->t('Embedding is inactive.'));
}
return $form;
}
}
