From e8490fe534bd67abe77a9cfebbff5fb0cb33f0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D0=BE?= =?UTF-8?q?=D1=80=D0=B5=D0=BF=D0=BE=D0=B2?= Date: Fri, 2 Mar 2018 08:56:45 +0300 Subject: [PATCH 1/2] Add Brick id to CSS class of element for simplify styling --- bricks.module | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bricks.module b/bricks.module index 35e57c4..404af36 100644 --- a/bricks.module +++ b/bricks.module @@ -7,6 +7,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Component\Utility\Html; /* BRICKS STORAGE */ @@ -78,6 +79,9 @@ function _bricks_nest_items($element, $items) { $items[$delta]['#label'] = $element['#items'][$delta]->entity->label(); $items[$delta]['#delta'] = $delta; $items[$delta]['#parent_delta'] = $parents[0]; + $items[$delta]['#attributes']['class'][] = 'brick'; + $items[$delta]['#attributes']['class'][] = 'brick--type--' . Html::cleanCssIdentifier($element['#items'][$delta]->entity->bundle()); + $items[$delta]['#attributes']['class'][] = 'brick--id--' . $element['#items'][$delta]->entity->id(); $items[$delta]['childs'] = []; if (!empty($element['#items'][$delta]->options['view_mode'])) { From 1be87e120bd89dbc449239a9cecaa78f7af42b2e Mon Sep 17 00:00:00 2001 From: Alexey Murz Korepov Date: Mon, 19 Mar 2018 23:07:28 +0300 Subject: [PATCH 2/2] Added views handler for Bricks Depth field --- bricks.module | 14 ++++ src/Plugin/views/field/BricksDepth.php | 100 +++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/Plugin/views/field/BricksDepth.php diff --git a/bricks.module b/bricks.module index 404af36..c145079 100644 --- a/bricks.module +++ b/bricks.module @@ -40,6 +40,20 @@ function _bricks_field_schema_alter(&$schema) { ]; } + +/** + * Implements hook_views_data_alter(). + */ + +function bricks_field_views_data_alter(array &$data, \Drupal\field\FieldStorageConfigInterface $field_storage) { + if($field_storage->getType() == 'bricks') { + $field_name = $field_storage->getName(); + foreach($data as &$item) { + $item[$field_name . '_depth']['field']['id'] = 'bricksdepth'; + } + } +} + /* BRICKS FORMATTING */ /** diff --git a/src/Plugin/views/field/BricksDepth.php b/src/Plugin/views/field/BricksDepth.php new file mode 100644 index 0000000..e1d58e5 --- /dev/null +++ b/src/Plugin/views/field/BricksDepth.php @@ -0,0 +1,100 @@ + '']; + $options['prefix'] = ['default' => '']; + $options['suffix'] = ['default' => '']; + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['style'] = [ + '#type' => 'select', + '#title' => $this->t('Style'), + '#options' => [ + '' => $this->t('Raw value'), + 'space' => $this->t('Spaces'), + 'line' => $this->t('Lines'), + 'tree' => $this->t('Tree'), + ], + '#default_value' => $this->options['style'], + ]; + $form['prefix'] = [ + '#type' => 'textfield', + '#title' => $this->t('Prefix'), + '#default_value' => $this->options['prefix'], + '#description' => $this->t('Text to put before the number, such as currency symbol.'), + ]; + $form['suffix'] = [ + '#type' => 'textfield', + '#title' => $this->t('Suffix'), + '#default_value' => $this->options['suffix'], + '#description' => $this->t('Text to put after the number, such as currency symbol.'), + ]; + parent::buildOptionsForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function render(ResultRow $values) { + $raw_value = $this->getValue($values); + + switch($this->options['style']) { + case 'space': + $indentation = [ + '#theme' => 'indentation', + '#size' => $raw_value, + ]; + $value =\Drupal::service('renderer')->render($indentation); + break; + case 'tree': + if($raw_value > 0) + $value = '  ' . str_repeat(' ', ($raw_value - 1) * 4) . '└'; + else + $value = ''; + break; + case 'line': + $value = '└' . str_repeat('─', $raw_value); + break; + default: + $value = $raw_value; + break; + } + + return [ + '#markup' => + $this->sanitizeValue($this->options['prefix'], 'xss') + . $value + . $this->sanitizeValue($this->options['suffix'], 'xss'), + ]; + } + +// /** +// * {@inheritdoc} +// */ +// public function clickSort($order) { +// $this->query->addOrderBy('node_field_data', 'created', $order); +// } +// +}