You are here

protected function Field::preprocessElement in Open Social 8

Same name and namespace in other branches
  1. 8.9 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  2. 8.2 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  3. 8.3 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  4. 8.4 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  5. 8.5 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  6. 8.6 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  7. 8.7 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()
  8. 8.8 themes/socialbase/src/Plugin/Preprocess/Field.php \Drupal\socialbase\Plugin\Preprocess\Field::preprocessElement()

Preprocess the variables array if an element is present.

Parameters

\Drupal\bootstrap\Utility\Element $element: The Element object.

\Drupal\bootstrap\Utility\Variables $variables: The Variables object.

Overrides PreprocessBase::preprocessElement

File

themes/socialbase/src/Plugin/Preprocess/Field.php, line 23

Class

Field
Pre-processes variables for the "field" theme hook.

Namespace

Drupal\socialbase\Plugin\Preprocess

Code

protected function preprocessElement(Element $element, Variables $variables) {

  // For each field that doesn't need a div to wrap the content in.
  switch ($element['#field_name']) {
    case 'field_profile_image':
    case 'field_profile_function':
    case 'field_profile_organization':
    case 'field_group_description':
    case 'field_group_address':
    case 'field_group_location':
    case 'field_group_image':
    case 'field_topic_image':
    case 'field_comment_body':
    case 'field_activity_output_text':
    case 'field_activity_entity':
    case 'field_profile_first_name':
    case 'field_profile_last_name':
      $variables['bare'] = TRUE;
      break;
    case 'field_call_to_action_link':
      $url_options = [
        'attributes' => [
          'class' => [
            'btn btn-primary',
          ],
        ],
      ];
      if (isset($element[0])) {
        $element[0]['#url']
          ->setOptions($url_options);
      }
      $url_options_1 = [
        'attributes' => [
          'class' => [
            'btn btn-default',
          ],
        ],
      ];
      if (isset($element[1])) {
        $element[1]['#url']
          ->setOptions($url_options_1);
      }
      break;
  }
  if ($element['#view_mode'] == 'teaser') {
    $variables['part_of_teaser'] = TRUE;
  }
  switch ($element['#entity_type']) {
    case 'node':
    case 'post':
      $variables['bare'] = TRUE;
      break;
  }
}