Exemplo n.º 1
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') {
    $form = parent::buildForm($form, $form_state, $field_key);
    $field = $this->field;

    $form['content'] = array(
      '#type' => 'text_format',
      '#title' => t('Field content'),
      '#default_value' => isset($field['properties']['content']['value']) ? $field['properties']['content']['value'] : '',
      '#format' => isset($field['properties']['content']['format']) ? $field['properties']['content']['format'] : 'plain_text',
      '#base_type' => 'textarea',
      '#required' => TRUE,
    );

    // Token support.
    if (\Drupal::moduleHandler()->moduleExists('token')) {
      $form['tokens'] = array(
        '#title' => t('Tokens'),
        '#type' => 'container',
        '#states' => array(
          'invisible' => array(
            'input[name="use_token"]' => array('checked' => FALSE),
          ),
        ),
      );
      $form['tokens']['help'] = array(
        '#theme' => 'token_tree',
        '#token_types' => 'all',
        '#global_types' => FALSE,
        '#dialog' => TRUE,
      );
    }

    return $form;
  }
Exemplo n.º 2
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') {
    $form = parent::buildForm($form, $form_state, $field_key);
    $field = $this->field;

    $manager = \Drupal::service('plugin.manager.ds');

    $fields = array();
    foreach ($manager->getDefinitions() as $plugin_id => $plugin_definition) {
      $entity_label = '';
      if (isset($plugin_definition['entity_type'])) {
        $entity_label .= ucfirst(str_replace('_', ' ', $plugin_definition['entity_type'])) . ' - ';
      }
      $fields[$plugin_id] = $entity_label . $plugin_definition['title'];
    }
    asort($fields);

    $form['ds_field_identity']['ds_plugin'] = array(
      '#type' => 'select',
      '#options' => $fields,
      '#title' => t('Fields'),
      '#required' => TRUE,
      '#default_value' => isset($field['properties']['ds_plugin']) ? $field['properties']['ds_plugin'] : '',
    );

    return $form;
  }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     // Create an instance of the block to find out if it has a config form.
     // Redirect to the block config form if there is one.
     /** @var $block BlockPluginInterface */
     $manager = \Drupal::service('plugin.manager.block');
     $block_id = $this->field['properties']['block'];
     $block = $manager->createInstance($block_id);
     $block_config_form = $block->blockForm([], new FormState());
     if ($block_config_form) {
         $url = new Url('ds.manage_block_field_config', array('field_key' => $this->field['id']));
         $form_state->setRedirectUrl($url);
     }
 }