diff --git a/CHANGELOG.md b/CHANGELOG.md index 685a568afcf65b7e27466ce16aab25c65eca7251..6c0c96e134d9602efc28d22f68bfe25c4e37ef70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,4 +37,12 @@ Add multiple arguments: https://www.drupal.org/node/2846625 Fix placeholder error: https://www.drupal.org/node/2838413 Remove redundant code Remove extra settings: https://www.drupal.org/node/2851184 -Add preexecute: https://www.drupal.org/node/2851058 \ No newline at end of file +Add preexecute: https://www.drupal.org/node/2851058 + +8.x-1.0-beta2 +More fixes to arguments: https://www.drupal.org/node/2888158 +Clean up install code: https://www.drupal.org/node/2862022 + +8.x-1.0-rc1 +Apply Details form type to title and argument options to prepare for advanced options module +Run codesniffer on code diff --git a/README.md b/README.md index c1d519a5b70fe6d4dce101847515ede19066e9e2..49c49ffa3530565e89a680b239827424adfd880d 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,4 @@ MAINTAINERS Current maintainers: * Kent Shelley (New Zeal) - https://www.drupal.org/u/new-zeal - * Joe Kersey (joekers) - https://www.drupal.org/u/joekers \ No newline at end of file + * Joe Kersey (joekers) - https://www.drupal.org/u/joekers diff --git a/modules/viewsreference_options/src/Field/FieldFormatter/ViewsReferenceOptionsFieldFormatter.php b/modules/viewsreference_options/src/Field/FieldFormatter/ViewsReferenceOptionsFieldFormatter.php index ef03face7a173c5e79ac26c9f79434ee8924b230..ecbb1814060e4cc4fa9cc153d1f3f2b0f6f49cdc 100644 --- a/modules/viewsreference_options/src/Field/FieldFormatter/ViewsReferenceOptionsFieldFormatter.php +++ b/modules/viewsreference_options/src/Field/FieldFormatter/ViewsReferenceOptionsFieldFormatter.php @@ -4,7 +4,6 @@ namespace Drupal\viewsreference_options\Plugin\Field\FieldFormatter; use Drupal\views\Views; use Drupal\Core\Field\FieldItemListInterface; -use Drupal\Core\Field\FormatterBase; use Drupal\Core\Form\FormStateInterface; /** @@ -34,8 +33,7 @@ class ViewsReferenceOptionsFieldFormatter extends ViewsReferenceFieldFormatter { public function settingsForm(array $form, FormStateInterface $form_state) { $form = parent::settingsForm($form, $form_state); - // Add new settings here - + // Add new settings here. return $form; } @@ -64,7 +62,7 @@ class ViewsReferenceOptionsFieldFormatter extends ViewsReferenceFieldFormatter { $elements = []; // We cannot use the parent function here so we need to replicate the build that occurs in viewsreference - // This could be avoided by having an independent function that processes the initial build + // This could be avoided by having an independent function that processes the initial build. foreach ($items as $delta => $item) { $view_name = $item->getValue()['target_id']; $display_id = $item->getValue()['display_id']; diff --git a/modules/viewsreference_options/src/Field/FieldWidget/ViewsReferenceOptionsWidget.php b/modules/viewsreference_options/src/Field/FieldWidget/ViewsReferenceOptionsWidget.php index a1cd8089c9c4d2eb4d4c84dd9c595b1704cfbd99..70c539319f29cb8bd0326f5def80f9be1cc4bd07 100644 --- a/modules/viewsreference_options/src/Field/FieldWidget/ViewsReferenceOptionsWidget.php +++ b/modules/viewsreference_options/src/Field/FieldWidget/ViewsReferenceOptionsWidget.php @@ -5,9 +5,8 @@ namespace Drupal\viewsreference_options\Plugin\Field\FieldWidget; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\Validator\ConstraintViolationInterface; -use Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget; -//use Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceTrait; +// Use Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceTrait;. /** * Plugin implementation of the 'entity_reference_autocomplete' widget. * @@ -54,7 +53,7 @@ class ViewsReferenceOptionsWidget extends ViewsReferenceWidget { $test = array('filled' => TRUE); $element = $this->fieldElement($element, $items, $delta, $test); - // Add extra options here + // Add extra options here. return $element; } diff --git a/src/Plugin/Field/FieldType/ViewsReferenceItem.php b/src/Plugin/Field/FieldType/ViewsReferenceItem.php index 7b8bee7eb2c0c4c0d8da74506d9fd6b98238b77d..fff6abec1b4c5057dc85e4fae414b6331d0389d2 100644 --- a/src/Plugin/Field/FieldType/ViewsReferenceItem.php +++ b/src/Plugin/Field/FieldType/ViewsReferenceItem.php @@ -90,7 +90,6 @@ class ViewsReferenceItem extends EntityReferenceItem implements $schema = parent::schema($field_definition); $target_type = $field_definition->getSetting('target_type'); $target_type_info = \Drupal::entityTypeManager()->getDefinition($target_type); - $properties = static::propertyDefinitions($field_definition)['target_id']; $schema['columns']['display_id'] = array( 'description' => 'The ID of the display.', 'type' => 'varchar_ascii', @@ -114,7 +113,7 @@ class ViewsReferenceItem extends EntityReferenceItem implements $schema['columns']['data'] = array( 'description' => 'Serialized data.', 'type' => 'text', - 'size' => 'big' + 'size' => 'big', ); $schema['indexes']['display_id'] = array('display_id'); diff --git a/src/Plugin/Field/FieldWidget/ViewsReferenceSelectWidget.php b/src/Plugin/Field/FieldWidget/ViewsReferenceSelectWidget.php index 25d930fe6ccd3e319050553fbcaec675cdc66b3b..df08491b21c673cc2c7020549d0bed216af0dfdd 100644 --- a/src/Plugin/Field/FieldWidget/ViewsReferenceSelectWidget.php +++ b/src/Plugin/Field/FieldWidget/ViewsReferenceSelectWidget.php @@ -47,4 +47,13 @@ class ViewsReferenceSelectWidget extends OptionsSelectWidget { return $select_element; } + /** + * {@inheritdoc} + */ + public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + // Options creates an array which we need to flatten. + $values = $this->massageValues($values, $form, $form_state); + return $values; + } + } diff --git a/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php b/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php index 451c65f9544d16577ecd50da6b52caa45990062a..b18490bf1a768d70d01a69161c89a1446f97d18b 100644 --- a/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php +++ b/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php @@ -77,7 +77,14 @@ trait ViewsReferenceTrait { ), ); - $element['title'] = array( + $element['options'] = array( + '#type' => 'details', + '#title' => t('Options'), + '#weight' => 10, + ); + + // Title and argument are the original options included in this module. + $element['options']['title'] = array( '#title' => 'Include View Title', '#type' => 'checkbox', '#default_value' => isset($items[$delta]->getValue()['title']) ? $items[$delta]->getValue()['title'] : '', @@ -89,7 +96,7 @@ trait ViewsReferenceTrait { ), ); - $element['argument'] = array( + $element['options']['argument'] = array( '#title' => 'Argument', '#type' => 'textfield', '#default_value' => isset($items[$delta]->getValue()['argument']) ? $items[$delta]->getValue()['argument'] : '', @@ -264,4 +271,19 @@ trait ViewsReferenceTrait { return $views_list; } + /** + * Helper function to flatten options array. + */ + public function massageValues(array $values, array $form, FormStateInterface $form_state) { + foreach ($values as $key => $value) { + if (is_array($value['options'])) { + foreach ($value['options'] as $ind => $option) { + $values[$key][$ind] = $option; + } + unset($value['options']); + } + } + return $values; + } + } diff --git a/src/Plugin/Field/FieldWidget/ViewsReferenceWidget.php b/src/Plugin/Field/FieldWidget/ViewsReferenceWidget.php index 95760359e91cdfbaf90de8b673f87c59a4168c0b..ed8b02feafcf5e16638d1e99a83d81f9b9214299 100644 --- a/src/Plugin/Field/FieldWidget/ViewsReferenceWidget.php +++ b/src/Plugin/Field/FieldWidget/ViewsReferenceWidget.php @@ -67,7 +67,10 @@ class ViewsReferenceWidget extends EntityReferenceAutocompleteWidget { * {@inheritdoc} */ public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { - return parent::massageFormValues($values, $form, $form_state); + $values = parent::massageFormValues($values, $form, $form_state); + // Options creates an array which we need to flatten. + $values = $this->massageValues($values, $form, $form_state); + return $values; } } diff --git a/viewsreference.install b/viewsreference.install index 69a59d07ec219fd6171477149456949e748f9779..e4e56738da680ff60a0d8aaf16932fa26eab6137 100644 --- a/viewsreference.install +++ b/viewsreference.install @@ -5,6 +5,9 @@ * Viewsreference install functions. */ +use Drupal\Core\Entity\Sql\SqlContentEntityStorage; + + /** * Update node fields already created with argument field. */ @@ -19,22 +22,23 @@ function viewsreference_update_8101() { viewsreference_update_viewsreference_fields('title'); } - /** * Update node fields already created with data field. */ function viewsreference_update_8102() { viewsreference_update_viewsreference_fields('data'); } + /** * Update all instances using viewsreference field type with new field. This is * called from hook_update_N() when new fields are added to the schema. * - * @param string $new_field_name The name of the new field to be added. + * @param string $new_field_name + * The name of the new field to be added. */ function viewsreference_update_viewsreference_fields($new_field_name) { - // Caches have to be cleared first to ensure new fields are detected in the code + // Caches have to be cleared first to ensure new fields are detected in the code. drupal_flush_all_caches(); // Retrieve list of all viewsreference fields mapped by entity type. @@ -46,7 +50,7 @@ function viewsreference_update_viewsreference_fields($new_field_name) { foreach (array_keys($fields) as $field_name) { $field_storage_definition = $manager->getFieldStorageDefinition($field_name, $entity_type_id); $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id); - if ($storage instanceof \Drupal\Core\Entity\Sql\SqlContentEntityStorage) { + if ($storage instanceof SqlContentEntityStorage) { $table_mapping = $storage->getTableMapping([ $field_name => $field_storage_definition, ]); @@ -67,4 +71,4 @@ function viewsreference_update_viewsreference_fields($new_field_name) { $manager->updateFieldStorageDefinition($field_storage_definition); } } -} \ No newline at end of file +} diff --git a/viewsreference.module b/viewsreference.module index cd057ce76c8aa3c6e977116ca7debc50d4bb15b9..9c4553d8c476bdc0ed5e66fb16d5765ea8441197 100644 --- a/viewsreference.module +++ b/viewsreference.module @@ -1,6 +1,6 @@ <?php /** - * @file module functions for viewsreference + * @file Module functions for viewsreference. */ /** @@ -11,15 +11,15 @@ function viewsreference_theme($existing, $type, $theme, $path) { 'viewsreference__view_title' => array( 'template' => 'viewsreference--view-title', 'render element' => 'variables', - ) + ), ); } /** * Implements HOOK_preprocess_HOOK(). - * + * * @param $variables */ function viewsreference_preprocess_viewsreference__view_title(&$variables) { $variables['title'] = $variables['variables']['#title']; -} \ No newline at end of file +}