Skip to content

Commit

Permalink
Revert "UHF-10643"
Browse files Browse the repository at this point in the history
This reverts commit d4bb7dd.

Accidental commit to dev branch.
  • Loading branch information
hyrsky committed Jan 27, 2025
1 parent d4bb7dd commit 329ab72
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 296 deletions.
69 changes: 0 additions & 69 deletions conf/cmi/search_api.index.suggestions.yml

This file was deleted.

29 changes: 0 additions & 29 deletions public/modules/custom/helfi_annif/helfi_annif.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

declare(strict_types=1);

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;

/**
* Create entity definitions for annif-fields.
*/
Expand Down Expand Up @@ -99,29 +96,3 @@ function helfi_annif_update_9003(): void {

// @todo remove obsolete field annif_keywords in a future update hook.
}

/**
* Updates entity fields for suggested_topics.
*/
function helfi_annif_update_9004(): void {
$fields['parent_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent ID'))
->setDescription(t('The ID of the parent entity of which this entity is referenced.'))
->setSetting('is_ascii', TRUE);

$fields['parent_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent type'))
->setDescription(t('The entity parent type to which this entity is referenced.'))
->setSetting('is_ascii', TRUE)
->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);

$fields['parent_instance'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent instance'))
->setDescription(t('The name of the instance where this entity is located at.'))
->setSetting('is_ascii', TRUE);

foreach ($fields as $name => $field) {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition($name, 'suggested_topics', 'helfi_annif', $field);
}
}
2 changes: 0 additions & 2 deletions public/modules/custom/helfi_annif/helfi_annif.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ services:
Drupal\helfi_annif\TextConverter\RenderTextConverter:
tags:
- { name: helfi_annif.text_converter, priority: -1 }

Drupal\helfi_annif\EventSubscriber\SearchApiSubscriber: ~
16 changes: 0 additions & 16 deletions public/modules/custom/helfi_annif/src/Entity/SuggestedTopics.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
])
->setDisplayConfigurable('view', TRUE);

$fields['parent_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent ID'))
->setDescription(t('The ID of the parent entity of which this entity is referenced.'))
->setSetting('is_ascii', TRUE);

$fields['parent_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent type'))
->setDescription(t('The entity parent type to which this entity is referenced.'))
->setSetting('is_ascii', TRUE)
->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);

$fields['parent_instance'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent instance'))
->setDescription(t('The name of the instance where this entity is located at.'))
->setSetting('is_ascii', TRUE);

return $fields;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
/**
* Defines the 'scored_entity_reference' field type.
*
* @property mixed $score Item score.
*
* @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem
* @see \Drupal\Core\Field\Plugin\Field\FieldType\FloatItem
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state):
/**
* {@inheritdoc}
*/
public function postSave($update): bool {
/** @var \Drupal\helfi_annif\Entity\SuggestedTopics $entity */
$parent = $this->getEntity();
$this->entity
->set('parent_id', $parent->id())
->save();
public function preSave() {
if ($this->hasNewEntity()) {
$this->entity->save();
}

return FALSE;
parent::preSave();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\helfi_annif\Entity\SuggestedTopics;
use Drupal\helfi_api_base\Environment\EnvironmentResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Defines the 'suggested_topics_reference' field widget.
Expand All @@ -30,20 +28,6 @@
)]
final class SuggestedTopicsReferenceWidget extends WidgetBase {

/**
* The environment resolver.
*/
private EnvironmentResolverInterface $environmentResolver;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new self($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings']);
$instance->environmentResolver = $container->get(EnvironmentResolverInterface::class);
return $instance;
}

/**
* {@inheritdoc}
*/
Expand All @@ -52,18 +36,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen

$hasTargetEntity = !empty($items[$delta]->target_id) && $items[$delta]->entity;

$project = NULL;
try {
$project = $this->environmentResolver->getActiveProject()->getName();
}
catch (\Exception) {
}

/** @var \Drupal\helfi_annif\Entity\SuggestedTopics $entity */
$entity = $hasTargetEntity ? $items[$delta]->entity : SuggestedTopics::create([
'parent_type' => $items->getEntity()->getEntityTypeId(),
'parent_instance' => $project,
]);
$entity = $hasTargetEntity ? $items[$delta]->entity : SuggestedTopics::create([]);

$element['entity'] = [
'#type' => 'value',
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 329ab72

Please sign in to comment.