/** * Helper to recursively build table rows to hold existing components. * * @param object $node * A node object the components belong to. * @param int $cid * A cid of the component. * @param array $component * A component. * @param int $level * The nesting level of this component. * @param array $form * The form that is being modified, passed by reference. * @param array $add_form * The add form which will be inserted under any previously added/edited * component. * * @see self::buildForm() */ protected function buildComponentsTableRow($node, $cid, $component, $level, &$form, &$add_form) { $row_class = ['draggable']; if (!webform_component_feature($component['type'], 'group')) { $row_class[] = 'tabledrag-leaf'; } if ($component['type'] == 'pagebreak') { $row_class[] = 'tabledrag-root'; $row_class[] = 'webform-pagebreak'; } $form['components'][$cid]['#attributes']['class'] = $row_class; $form['components'][$cid]['#attributes']['data-cid'] = $cid; $indentation = ''; if ($level >= 1) { $indentation = ['#theme' => 'indentation', '#size' => $level]; $indentation = drupal_render($indentation); } $form['components'][$cid]['name'] = ['#prefix' => $indentation, '#markup' => Xss::filter($component['name']), '#attributes' => ['class' => ['webform-component-name', $component['type'] == 'pagebreak' ? 'webform-pagebreak' : '']]]; $form['components'][$cid]['type'] = ['#markup' => $form['#component_options'][$component['type']], '#attributes' => ['class' => ['webform-component-type']]]; // Create a presentable value. if (Unicode::strlen($component['value']) > 30) { $component['value'] = Unicode::substr($component['value'], 0, 30); $component['value'] .= '...'; } $component['value'] = SafeMarkup::checkPlain($component['value']); $form['components'][$cid]['value'] = ['#markup' => $component['value'] == '' ? '-' : $component['value'], '#attributes' => ['class' => ['webform-component-value']]]; $form['components'][$cid]['required'] = ['#type' => 'checkbox', '#title' => $this->t('Required'), '#title_display' => 'invisible', '#default_value' => $component['required'], '#access' => webform_component_feature($component['type'], 'required'), '#attributes' => ['class' => ['webform-component-required']]]; $form['components'][$cid]['weight'] = ['#type' => 'textfield', '#title' => $this->t('Weight for @title', ['@title' => $component['name']]), '#title_display' => 'invisible', '#size' => 4, '#delta' => count($node->webform['components']) > 10 ? count($node->webform['components']) : 10, '#default_value' => $form['#component_weights'][$cid], '#attributes' => ['class' => ['webform-weight']]]; $form['components'][$cid]['parent']['cid'] = ['#parents' => ['components', $cid, 'cid'], '#type' => 'hidden', '#default_value' => $component['cid'], '#attributes' => ['class' => ['webform-cid']]]; $form['components'][$cid]['parent']['pid'] = ['#parents' => ['components', $cid, 'pid'], '#type' => 'hidden', '#default_value' => $component['pid'], '#attributes' => ['class' => ['webform-pid']]]; $form['components'][$cid]['operations'] = ['#type' => 'operations', '#links' => []]; // @todo Fix these links once the routes exist. $form['components'][$cid]['operations']['#links']['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('webform.component_edit_form', ['node' => $node->id(), 'component' => $cid])]; $form['components'][$cid]['operations']['#links']['clone'] = ['title' => $this->t('Clone'), 'url' => Url::fromRoute('entity.node.webform', ['node' => $node->id()])]; $form['components'][$cid]['operations']['#links']['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('webform.component_delete_form', ['node' => $node->id(), 'component' => $cid])]; if (isset($component['children']) && is_array($component['children'])) { foreach ($component['children'] as $cid => $component) { $this->buildComponentsTableRow($node, $cid, $component, $level + 1, $form, $add_form); } } // Add the add form if this was the last edited component. if (isset($_GET['cid']) && $component['cid'] == $_GET['cid'] && $add_form) { $add_form['name']['#prefix'] = $indentation; $form['components']['add'] = $add_form; $add_form = FALSE; } }
/** * {@inheritdoc} */ public function getQuestion() { $component_type = $this->node->webform['components'][$this->component['cid']]['type']; if (webform_component_feature($component_type, 'group')) { return $this->t('Delete the %name fieldset?', ['%name' => $this->node->webform['components'][$this->component['cid']]['name']]); } else { return $this->t('Delete the %name component?', ['%name' => $this->node->webform['components'][$this->component['cid']]['name']]); } }