Skip to content
Snippets Groups Projects
Commit d71a9193 authored by Kent Shelley's avatar Kent Shelley
Browse files

add options details and run codesniffer

parent 4b58c073
Branches options
Tags
No related merge requests found
......@@ -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
......@@ -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
......@@ -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'];
......
......@@ -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;
}
......
......@@ -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');
......
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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
}
<?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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment