/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $grouping = NULL) { // Load logo image. $rendered_image = NULL; if (!empty($grouping->logo_fid)) { $file = File::load($grouping->logo_fid); if ($file) { $logo_url = ImageStyle::load('ea_groupings_200x200')->buildUrl($file->getFileUri()); $image_array = array('#theme' => 'image', '#uri' => $logo_url, '#alt' => $this->t('Logo for @grouping', array('@grouping' => $grouping->title)), '#title' => $this->t('@grouping', array('@grouping' => $grouping->title))); $rendered_image = \Drupal::service('renderer')->render($image_array); } } // Construct form. $form = array(); $form['gid'] = array('#type' => 'value', '#value' => $grouping->gid); $form['add'] = array('#type' => 'fieldset', '#description' => $this->t('Update grouping'), '#title' => $this->t('Edit grouping')); $form['add']['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('Title of grouping'), '#size' => 20, '#maxlength' => 20, '#required' => FALSE, '#default_value' => $grouping->title); $form['add']['description'] = array('#type' => 'textarea', '#title' => $this->t('Description'), '#description' => $this->t('A short description of the grouping'), '#required' => FALSE, '#default_value' => $grouping->description); $form['add']['logo'] = array('#type' => 'markup', '#markup' => $rendered_image); $form['add']['logo_fid'] = array('#title' => $this->t('Update logo'), '#type' => 'managed_file', '#description' => $this->t('Upload a logo for the grouping'), '#default_value' => NULL, '#upload_location' => 'public://logos/'); $form['add']['time_zone'] = array('#title' => $this->t('Timezone'), '#type' => 'select', '#description' => $this->t('Select a time zone for the grouping'), '#options' => _ea_groupings_get_time_zones(), '#default_value' => $grouping->time_zone); $form['add']['parent_gid'] = array('#type' => 'select', '#description' => $this->t('Select a parent grouping'), '#options' => _ea_groupings_get_groupings_list(FALSE, $grouping->gid), '#disabled' => _ea_groupings_is_parent($grouping->gid), '#default_value' => $grouping->parent_gid); $form['add']['submit'] = array('#type' => 'submit', '#name' => 'add_group', '#value' => $this->t('Update grouping'), '#weight' => 100); $form['add']['old_title'] = array('#type' => 'value', '#value' => $grouping->title); $form['add']['old_logo_fid'] = array('#type' => 'value', '#value' => $grouping->logo_fid); $form['add']['old_parent_gid'] = array('#type' => 'value', '#value' => $grouping->parent_gid); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $parent_gid = NULL) { $form = array(); $form['add'] = array('#type' => 'details', '#description' => t('Add a grouping to the grouping table.'), '#title' => t('Add grouping')); $form['add']['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('Title of grouping.'), '#size' => 20, '#maxlength' => 20, '#required' => FALSE); $form['add']['description'] = array('#type' => 'textarea', '#title' => $this->t('Description'), '#description' => $this->t('A short description of the grouping.'), '#required' => FALSE); $form['add']['logo_fid'] = array('#title' => $this->t('Logo'), '#type' => 'managed_file', '#description' => $this->t('Upload a logo for the grouping.'), '#upload_location' => 'public://files/logos/', '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg'), 'file_validate_size' => array(1000000), 'file_validate_image_resolution' => array('1920x1080'))); $form['add']['time_zone'] = array('#title' => $this->t('Timezone'), '#type' => 'select', '#description' => $this->t('Select a time zone for the grouping.'), '#options' => _ea_groupings_get_time_zones()); $form['add']['parent_gid'] = array('#type' => 'select', '#description' => $this->t('Select a parent grouping'), '#options' => _ea_groupings_get_groupings_list(FALSE, NULL), '#default_value' => $parent_gid); $form['add']['submit'] = array('#type' => 'submit', '#name' => 'add_group', '#value' => $this->t('Add grouping'), '#weight' => 100); return $form; }