You are here

function wingsuit_link_link_attributes_plugin_alter in Gin Layout Builder 8.2

Add UIPatterns settings as link widget options.

Parameters

array[] $plugins: Link attribute plugin definitions.

File

modules/wingsuit_link/wingsuit_link.module, line 12

Code

function wingsuit_link_link_attributes_plugin_alter(array &$plugins) {
  $pattern = UiPatterns::getManager()
    ->getDefinition('button');
  if ($pattern !== NULL) {
    if (count($pattern
      ->getVariantsAsOptions()) > 0) {
      $options = [
        '' => t('- Use default -'),
      ];
      $plugins['variant'] = [
        'title' => t('Variant'),
        'type' => 'select',
        'options' => $options + $pattern
          ->getVariantsAsOptions(),
      ];
    }
    $settings = UiPatternsSettings::getPatternDefinitionSettings($pattern);
    foreach ($settings as $setting) {
      if (in_array($setting
        ->getType(), [
        'select',
        'radios',
      ])) {
        $options = [
          '' => t('- Use default -'),
        ];
        $options += $setting
          ->getOptions() ?? [];
        $plugins[$setting
          ->getName()] = [
          'title' => $setting
            ->getLabel(),
          'type' => $setting
            ->getType(),
          'options' => $options,
        ];
      }
      if (in_array($setting
        ->getType(), [
        'boolean',
      ])) {
        $options = [
          '' => t('- Use default -'),
          1 => t('True'),
          0 => t('False'),
        ];
        $plugins[$setting
          ->getName()] = [
          'title' => $setting
            ->getLabel(),
          'type' => 'select',
          'options' => $options,
        ];
      }
    }
  }
}