You are here

public function PrintfriendlyConfigForm::buildForm in PrintFriendly & PDF 8

Same name and namespace in other branches
  1. 8.3 src/Form/PrintfriendlyConfigForm.php \Drupal\printfriendly\Form\PrintfriendlyConfigForm::buildForm()
  2. 8.2 src/Form/PrintfriendlyConfigForm.php \Drupal\printfriendly\Form\PrintfriendlyConfigForm::buildForm()

Form constructor.

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 form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/PrintfriendlyConfigForm.php, line 28
Contains \Drupal\printfriendly\Form\printfriendlyConfigForm.

Class

PrintfriendlyConfigForm

Namespace

Drupal\printfriendly\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('printfriendly.settings');
  $form = parent::buildForm($form, $form_state);
  $form['printfriendly_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Content Types'),
    '#description' => t('Configure where the printfriendly button should appear.'),
    '#options' => node_type_get_names(),
    '#default_value' => $config
      ->get('printfriendly_types', array()),
  );
  $form['printfriendly_display'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Button display'),
    '#description' => t('Select content displays that the button should appear.'),
    '#options' => array(
      'teaser' => t('Teaser'),
      'full' => t('Full content page'),
    ),
    '#default_value' => array_filter($config
      ->get('printfriendly_display')),
  );

  // Add more features here
  $form['printfriendly_features'] = array(
    '#type' => 'fieldset',
    '#title' => t('Features'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['printfriendly_features']['printfriendly_page_header'] = array(
    '#type' => 'select',
    '#title' => t('Page header'),
    '#options' => array(
      'default_logo' => 'My Website Icon',
      'custom_logo' => 'Upload an Image',
    ),
    '#default_value' => $config
      ->get('printfriendly_page_header', 'default_logo'),
  );
  $form['printfriendly_features']['printfriendly_page_custom_header'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter URL'),
    '#description' => t('Put full path of the file like http://devt.drupalchamp.org/sites/default/files/drupal-logo.png'),
    '#states' => array(
      'invisible' => array(
        ':input[name="printfriendly_page_header"]' => array(
          array(
            'value' => t('default_logo'),
          ),
        ),
      ),
    ),
    '#default_value' => $config
      ->get('printfriendly_page_custom_header', ''),
  );
  $form['printfriendly_features']['printfriendly_tagline'] = array(
    '#type' => 'textfield',
    '#title' => t('Header tagline'),
    '#default_value' => $config
      ->get('printfriendly_tagline', ''),
    '#description' => t('Add a specific tagline to the header.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="printfriendly_page_header"]' => array(
          array(
            'value' => t('default_logo'),
          ),
        ),
      ),
    ),
  );
  $form['printfriendly_features']['printfriendly_click_delete'] = array(
    '#type' => 'select',
    '#title' => t('Click-to-delete'),
    '#options' => array(
      '0' => 'Allow',
      '1' => 'Not Allow',
    ),
    '#default_value' => $config
      ->get('printfriendly_click_delete', '0'),
  );
  $form['printfriendly_features']['printfriendly_images'] = array(
    '#type' => 'select',
    '#title' => t('Images'),
    '#options' => array(
      '0' => 'Include',
      '1' => 'Exclude',
    ),
    '#default_value' => $config
      ->get('printfriendly_images', '0'),
  );
  $form['printfriendly_features']['printfriendly_image_style'] = array(
    '#type' => 'select',
    '#title' => t('Image style'),
    '#options' => array(
      'right' => 'Align Right',
      'left' => 'Align Left',
      'none' => 'Align None',
      'block' => 'Center/Block',
    ),
    '#default_value' => $config
      ->get('printfriendly_image_style', 'right'),
  );
  $form['printfriendly_features']['printfriendly_email'] = array(
    '#type' => 'select',
    '#title' => t('Email'),
    '#options' => array(
      '0' => 'Allow',
      '1' => 'Not Allow',
    ),
    '#default_value' => $config
      ->get('printfriendly_email', '0'),
  );
  $form['printfriendly_features']['printfriendly_pdf'] = array(
    '#type' => 'select',
    '#title' => t('PDF'),
    '#options' => array(
      '0' => 'Allow',
      '1' => 'Not Allow',
    ),
    '#default_value' => $config
      ->get('printfriendly_pdf', '0'),
  );
  $form['printfriendly_features']['printfriendly_print'] = array(
    '#type' => 'select',
    '#title' => t('Print'),
    '#options' => array(
      '0' => 'Allow',
      '1' => 'Not Allow',
    ),
    '#default_value' => $config
      ->get('printfriendly_print', '0'),
  );
  $form['printfriendly_features']['printfriendly_custom_css'] = array(
    '#type' => 'textfield',
    '#description' => t('Put full path of the file like http://devt.drupalchamp.org/sites/default/files/printfriendly.css'),
    '#title' => t('Custom css url'),
    '#default_value' => $config
      ->get('printfriendly_custom_css', ''),
  );
  $form['printfriendly_features']['printfriendly_website_protocol'] = array(
    '#type' => 'select',
    '#title' => t('Website protocol'),
    '#options' => array(
      'http' => 'HTTP',
      'https' => 'HTTPS',
    ),
    '#default_value' => $config
      ->get('printfriendly_website_protocol', 'http'),
  );
  $img_path = drupal_get_path('module', 'printfriendly') . '/images';
  $results = file_scan_directory($img_path, '/^.*\\.(gif|png|jpg|GIF|PNG|JPG)$/');
  $options = array();
  foreach ($results as $image) {
    $options[$image->filename] = '<img src="' . file_create_url($image->uri) . '" />';
  }
  ksort($options);
  $form['printfriendly_image'] = array(
    '#type' => 'radios',
    '#title' => t('Choose button'),
    '#options' => $options,
    '#default_value' => $config
      ->get('printfriendly_image', 'button-print-grnw20.png'),
  );
  $form['support-link'] = array(
    '#markup' => 'Need help or have suggestions? <a href="mailto:support@printfriendly.com">Support@PrintFriendly.com</a>',
    '#weight' => 1000,
  );
  return $form;
}