public function QuickNodeBlock::ajaxCallback in Quick Node Block 8
Updates the options of a select list.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The updated form element.
File
- src/
Plugin/ Block/ QuickNodeBlock.php, line 177
Class
- QuickNodeBlock
- Provides a Node Block with his display.
Namespace
Drupal\quick_node_block\Plugin\BlockCode
public function ajaxCallback(array $form, FormStateInterface $form_state) {
// Get the currently selected node.
$element = $form_state
->getTriggeringElement();
$node_title = $element['#value'];
// Get nid.
preg_match("/.+\\s\\(([^\\)]+)\\)/", $node_title, $matches);
$nid = $matches[1];
// Get bundle.
$storage = $this->entityTypeManager
->getStorage('node');
$node = $storage
->load($nid);
$content_type = $node
->getType();
// Get view mode.
$view_mode = $this->entityDisplay
->getViewModeOptionsByBundle('node', $content_type);
$form['settings']['quick_display']['#options'] = $view_mode;
return $form['settings']['quick_display'];
}