Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function fieldSettingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::fieldSettingsForm($form, $form_state);
     $range = $this->getSetting('range');
     $element['range'] = array('#type' => 'textfield', '#title' => t('Range'), '#description' => t('The range of weights available to select. For
     example, a range of 20 will allow you to select a weight between -20
     and 20.'), '#default_value' => $range, '#size' => 5);
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function fieldSettingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::fieldSettingsForm($form, $form_state);
     $mc_list_id = $this->getFieldDefinition()->getSetting('mc_list_id');
     if (empty($mc_list_id)) {
         drupal_set_message(t('Select a list to sync with on the Field Settings tab before configuring the field instance.'), 'error');
         return $element;
     }
     $this->definition;
     $instance_settings = $this->definition->getSettings();
     $element['show_interest_groups'] = array('#title' => "Enable Interest Groups", '#type' => "checkbox", '#default_value' => $instance_settings['show_interest_groups']);
     $element['interest_groups_label'] = array('#title' => "Interest Groups Label", '#type' => "textfield", '#default_value' => !empty($instance_settings['show_interest_groups']) ? $instance_settings['show_interest_groups'] : 'Interest Groups');
     $element['merge_fields'] = array('#type' => 'fieldset', '#title' => t('Merge Fields'), '#description' => t('Multi-value fields will only sync their first value to Mailchimp, as Mailchimp does not support multi-value fields.'), '#tree' => TRUE);
     $element['unsubscribe_on_delete'] = array('#title' => "Unsubscribe on deletion", '#type' => "checkbox", '#description' => t('Unsubscribe entities from this list when they are deleted.'), '#default_value' => $instance_settings['unsubscribe_on_delete']);
     $mv_defaults = $instance_settings['merge_fields'];
     $mergevars = mailchimp_get_mergevars(array($mc_list_id));
     $fields = $this->getFieldmapOptions($this->getFieldDefinition()->entity_type, $this->getFieldDefinition()->bundle);
     $required_fields = $this->getFieldmapOptions($this->getFieldDefinition()->entity_type, $this->getFieldDefinition()->bundle, TRUE);
     // Prevent this subscription field appearing as a merge field option.
     $field_name = $this->getFieldDefinition()->getName();
     unset($fields[$field_name]);
     $fields_flat = OptGroup::flattenOptions($fields);
     foreach ($mergevars[$mc_list_id]['merge_vars'] as $mergevar) {
         $default_value = isset($mv_defaults[$mergevar['tag']]) ? $mv_defaults[$mergevar['tag']] : -1;
         $element['merge_fields'][$mergevar['tag']] = array('#type' => 'select', '#title' => SafeMarkup::checkPlain($mergevar['name']), '#default_value' => array_key_exists($default_value, $fields_flat) ? $default_value : '', '#required' => $mergevar['req']);
         if (!$mergevar['req'] || $mergevar['tag'] === 'EMAIL') {
             $element['merge_fields'][$mergevar['tag']]['#options'] = $fields;
             if ($mergevar['tag'] === 'EMAIL') {
                 $element['merge_fields'][$mergevar['tag']]['#description'] = t('Any entity with an empty or invalid email address field value will simply be ignored by the Mailchimp subscription system. <em>This is why the Email field is the only required merge field which can sync to non-required fields.</em>');
             }
         } else {
             $element['merge_fields'][$mergevar['tag']]['#options'] = $required_fields;
             $element['merge_fields'][$mergevar['tag']]['#description'] = t("Only 'required' and 'calculated' fields are allowed to be synced with Mailchimp 'required' merge fields.");
         }
     }
     return $element;
 }