public function MultigraphForm::removeSensorSubmit in Monitoring 8
Removes sensor from entity when 'Remove' button is pressed for sensor.
Parameters
array $form: The form structure array
\Drupal\Core\Form\FormStateInterface $form_state: The form state structure.
File
- modules/
multigraph/ src/ Form/ MultigraphForm.php, line 232 - Contains \Drupal\monitoring_multigraph\Form\MultigraphForm.
Class
- MultigraphForm
- Multigraph settings form controller.
Namespace
Drupal\monitoring_multigraph\FormCode
public function removeSensorSubmit(array $form, FormStateInterface $form_state) {
$form_state
->setRebuild();
/** @var \Drupal\monitoring_multigraph\MultigraphInterface $multigraph */
$multigraph = $this->entity;
// Remove sensor as indicated by triggering_element.
$button_name = $form_state
->getTriggeringElement()['#name'];
$sensor_name = substr($button_name, strlen('remove_'));
$sensor_label = $this->entityTypeManager
->getStorage('monitoring_sensor_config')
->load($sensor_name)
->getLabel();
$multigraph
->removeSensor($sensor_name);
$this
->messenger()
->addWarning($this
->t('Sensor "@sensor_label" removed. You have unsaved changes.', array(
'@sensor_label' => $sensor_label,
)));
}