You are here

class BlockFieldWidget in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  2. 8 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  3. 8.2 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  4. 8.3 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  5. 8.4 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  6. 8.5 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  7. 8.6 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  8. 8.7 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  9. 8.8 modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  10. 10.3.x modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  11. 10.0.x modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget
  12. 10.2.x modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget

Plugin implementation of the 'block_field' widget.

Plugin annotation


@FieldWidget(
  id = "block_field_default",
  label = @Translation("Block field"),
  field_types = {
    "block_field"
  }
)

Hierarchy

  • class \Drupal\social_landing_page\Plugin\Field\FieldWidget\BlockFieldWidget extends \Drupal\block_field\Plugin\Field\FieldWidget\BlockFieldWidget

Expanded class hierarchy of BlockFieldWidget

File

modules/social_features/social_landing_page/src/Plugin/Field/FieldWidget/BlockFieldWidget.php, line 20

Namespace

Drupal\social_landing_page\Plugin\Field\FieldWidget
View source
class BlockFieldWidget extends BlockFieldWidgetBase {

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items, $delta, $element, $form, $form_state);
    if ($element['#field_parents'][0] != 'field_landing_page_section') {
      return $element;
    }
    $options = [];
    $groups = [
      $this
        ->t('Lists (Views)')
        ->render() => $this
        ->t('Basic'),
      $this
        ->t('Social Landing Page')
        ->render() => $this
        ->t('Basic'),
    ];
    $blocks = [
      'activity_overview_block' => $this
        ->t('Community statistics'),
      'views_block:activity_stream-block_stream_homepage_without_post' => $this
        ->t('Personalised activity stream'),
      'views_block:activity_stream-block_stream_homepage' => $this
        ->t('Personalised activity stream (with post form)'),
      'views_block:community_activities-block_stream_landing' => $this
        ->t('Complete community activity stream'),
      'views_block:community_activities-block_stream_landing_with_post' => $this
        ->t('Complete community activity stream (with post form)'),
      'views_block:latest_topics-block_latest_topics' => $this
        ->t('Latest topics'),
      'views_block:newest_groups-block_newest_groups' => $this
        ->t('Newest groups'),
      'views_block:newest_users-block_newest_users' => $this
        ->t('Newest users'),
      'views_block:upcoming_events-block_community_events' => $this
        ->t('Upcoming community events'),
    ];
    foreach ($element['plugin_id']['#options'] as $title => $items) {
      if (isset($groups[$title])) {
        $title = $groups[$title];
      }
      else {
        $title = $this
          ->t('Extra');
      }
      $title = $title
        ->render();
      if (!isset($options[$title])) {
        $options[$title] = [];
      }
      foreach ($items as $key => $value) {
        if (isset($blocks[$key])) {
          $value = $blocks[$key];
        }
        $options[$title][$key] = $value;
      }
    }
    foreach ($options as &$option) {
      asort($option);
    }
    $element['plugin_id']['#options'] = $options;
    return $element;
  }

}

Members