You are here

public function EditorNoteHelperService::getNotesByEntityAndField in Editor Notes 8

Returns Editor Note entity ids for passed entity and field name.

Parameters

int $host_entity_id: Host entity ID.

string $field_machine_name: Field machine name.

array $settings: Widget settings.

Return value

mixed A single field from the next record, or FALSE if there is no next record.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to EditorNoteHelperService::getNotesByEntityAndField()
EditorNoteHelperService::getWidgetAjaxReplaceCommand in src/EditorNoteHelperService.php
Returns ajax replace command for refreshing field widget.

File

src/EditorNoteHelperService.php, line 137

Class

EditorNoteHelperService
Class EditorNoteHelperService.

Namespace

Drupal\editor_note

Code

public function getNotesByEntityAndField($host_entity_id, $field_machine_name, $settings = []) {
  $query = $this->connection
    ->select('editor_note', 'en');
  $query
    ->fields('en', [
    'id',
  ]);
  $query
    ->condition('en.entity_id', $host_entity_id);
  $query
    ->condition('en.field_machine_name', $field_machine_name);
  $query
    ->orderBy('en.changed', 'DESC');
  if (!empty($settings['limit']) && $settings['limit'] > 0) {
    $query
      ->range(0, $settings['limit']);

    //      Not fully implemented pagination flow.
    //      @see https://www.drupal.org/project/editor_note/issues/3087584
    //      $query = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')
    //        ->limit($settings['limit']);
  }
  $record_ids = $query
    ->execute()
    ->fetchAllKeyed(0, 0);
  if ($record_ids) {
    return $this->entityTypeManager
      ->getStorage('editor_note')
      ->loadMultiple($record_ids);
  }
  return [];
}