You are here

public function VueBlock::buildPropertyString in Decoupled Blocks: Vue.js 8

Create a string of Vue Component property parameters.

Return value

string A string of property elements to inject into the DOM directive.

1 call to VueBlock::buildPropertyString()
VueBlock::build in src/Plugin/Block/VueBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/VueBlock.php, line 148

Class

VueBlock
Exposes a Vue component as a block.

Namespace

Drupal\pdb_vue\Plugin\Block

Code

public function buildPropertyString() {
  $props_string = '';
  if (isset($this->configuration['pdb_configuration'])) {
    $props = $this->configuration['pdb_configuration'];
    foreach ($props as $field => $value) {

      // Determine if the property should use v-bind (:shorthand) due to the
      // value being numeric.
      $bind = '';
      if (is_numeric($value)) {
        $bind = ':';
      }

      // Convert camelCase to kebab-case.
      $field = $this
        ->convertKebabCase($field);

      // Create the string of properties.
      $props_string .= ' ' . $bind . $field . '="' . $value . '"';
    }
  }
  return $props_string;
}