Commit 55ab0302 authored by generalredneck's avatar generalredneck

WIP: A little more refactoring.

parent b78f496a
......@@ -3,14 +3,28 @@
namespace Drupal\views_natural_sort\Form;
use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_natural_sort\ViewsNaturalSortService;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines a form that configures Views Natural Sort's settings.
*/
class ConfigurationForm extends ConfigFormBase {
protected $viewsNaturalSort;
public function __construct(ViewsNaturalSortService $viewsNaturalSort) {
$this->viewsNaturalSort = $viewsNaturalSort;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('views_natural_sort.service')
);
}
/**
* {@inheritdoc}
*/
......@@ -123,7 +137,7 @@ class ConfigurationForm extends ConfigFormBase {
* The form state.
*/
public function submitFormReindexOnly(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('Index rebuild has completed.'));
$this->viewsNaturalSort->queueDataForRebuild();
}
}
<?php
namespace Drupal/views_natural_sort/Plugin/QueueWorker;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;\
use Drupal\views_natural_sort\ViewsNaturalSortService;
/**
* Provides base functionality for the NodePublish Queue Workers.
*
* @QueueWorker(
* id = "views_natural_sort_entity_index",
* title = @Translation("Views Natural Sort Entity Index"),
* )
*/
class EntityIndexer extends QueueWorkerBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManager $entityTypeManager, ViewsNaturalSortService $viewsNaturalSortService) {
$this->entityTypeManager = $entityTypeManager
$this->viewsNaturalSortService = $viewsNaturalSortService
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$container->get('entity_type.manager'),
$container->get('views_natural_sort.service')
);
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
$entity = $this->entityTypeManager
->getStorage($data['entity_type'])
->load($data['entity_id']);
if ($entity) {
$this->viewsNaturalSortService->storeIndexRecordsFromEntity($entity);
}
}
}
......@@ -148,6 +148,10 @@ class ViewsNaturalSortService {
}
public function storeIndexRecordsFromEntity(EntityInterface $entity) {
// TODO: Consider abstracting this out. The creation and storage of records
// should be handled by a converter class that interacts with specific
// IndexRecordTypes and creates IndexRecords. Those would probably be called
// directly and have nothign to do with this service.
$entity_type = $entity->getEntityTypeId();
$supported_entity_properties = $this->getViewsSupportedEntityProperties();
foreach ($supported_entity_properties[$entity_type] as $field => $field_info) {
......
......@@ -41,7 +41,8 @@ function views_natural_sort_module_implements_alter(&$implements, $hook) {
* @Not-Rewritten
*/
function views_natural_sort_views_natural_sort_get_entry_types() {
$supported_entity_properties = views_natural_sort_get_views_configurable_properties();
$service = Drupal::service('views_natural_sort.service');
$supported_entity_properties = $service->getViewsSupportedEntityProperties();
$entry_types = array();
foreach ($supported_entity_properties as $entity_type => $properties) {
foreach ($properties as $property => $schema_info) {
......@@ -135,26 +136,3 @@ function views_natural_sort_remove($index_entry) {
}
$query->execute();
}
/**
* Returns a list of properties that we know views will allow us to alter.
*
* This list of properties is more realistic than "supported properties" because
* it factors in what views actually contains handlers for. This is used by
* all the administration functions to determine what properties need to be
* affected by VNS.
*
* @return mixed
* Returns an array formatted as views_natural_sort_get_supported_entity_properties
* or FALSE when views hasn't been initialized yet.
*
* @see views_natural_sort_get_supported_entity_properties
* @STUBBED
*/
function views_natural_sort_get_views_configurable_properties() {
$views_configurable_properties = &drupal_static(__FUNCTION__, array());
if (empty($supported_properties)) {
$supported_entity_properties = views_natural_sort_get_supported_entity_properties();
}
return $supported_entity_properties;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment