You are here

function _social_topic_change_topic_icon_ajax in Open Social 10.1.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_topic/social_topic.module \_social_topic_change_topic_icon_ajax()
  2. 10.0.x modules/social_features/social_topic/social_topic.module \_social_topic_change_topic_icon_ajax()
  3. 10.2.x modules/social_features/social_topic/social_topic.module \_social_topic_change_topic_icon_ajax()

Ajax callback to change topic type icon.

1 string reference to '_social_topic_change_topic_icon_ajax'
social_topic_form_taxonomy_term_topic_types_form_alter in modules/social_features/social_topic/social_topic.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_topic/social_topic.module, line 349
The Social topic module.

Code

function _social_topic_change_topic_icon_ajax(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $icon = $form_state
    ->getValue('field_topic_type_icon')[0]['value'];
  $replaced = [
    '#type' => 'inline_template',
    '#template' => '<div class="icon-svg-wrapper" data-href="#' . $icon . '"><svg class="selected-svg"><use xlink:href="#' . $icon . '"></use></svg>{{ svg_icons|raw }}</div>',
    '#context' => [
      'svg_icons' => file_get_contents(drupal_get_path('theme', 'socialbase') . '/assets/icons/icons.svg'),
    ],
  ];
  $response
    ->addCommand(new ReplaceCommand('.icon-svg-wrapper', $replaced));
  return $response;
}