Chris@0: t('Duplicate of @label', ['@label' => $this->entity->label()]); Chris@0: Chris@0: $form['label'] = [ Chris@0: '#type' => 'textfield', Chris@0: '#title' => $this->t('View name'), Chris@0: '#required' => TRUE, Chris@0: '#size' => 32, Chris@0: '#maxlength' => 255, Chris@0: '#default_value' => $this->t('Duplicate of @label', ['@label' => $this->entity->label()]), Chris@0: ]; Chris@0: $form['id'] = [ Chris@0: '#type' => 'machine_name', Chris@0: '#maxlength' => 128, Chris@0: '#machine_name' => [ Chris@0: 'exists' => '\Drupal\views\Views::getView', Chris@0: 'source' => ['label'], Chris@0: ], Chris@0: '#default_value' => '', Chris@0: '#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'), Chris@0: ]; Chris@0: Chris@0: return $form; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function actions(array $form, FormStateInterface $form_state) { Chris@0: $actions['submit'] = [ Chris@0: '#type' => 'submit', Chris@0: '#value' => $this->t('Duplicate'), Chris@0: ]; Chris@0: return $actions; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Form submission handler for the 'clone' action. Chris@0: * Chris@0: * @param array $form Chris@0: * An associative array containing the structure of the form. Chris@0: * @param \Drupal\Core\Form\FormStateInterface $form_state Chris@0: * A reference to a keyed array containing the current state of the form. Chris@0: */ Chris@0: public function submitForm(array &$form, FormStateInterface $form_state) { Chris@0: $this->entity = $this->entity->createDuplicate(); Chris@0: $this->entity->set('label', $form_state->getValue('label')); Chris@0: $this->entity->set('id', $form_state->getValue('id')); Chris@0: $this->entity->save(); Chris@0: Chris@0: // Redirect the user to the view admin form. Chris@18: $form_state->setRedirectUrl($this->entity->toUrl('edit-form')); Chris@0: } Chris@0: Chris@0: }