getDisplayModeOptions example

// Non-field elements.     foreach ($extra_fields as $field_id => $extra_field) {
      $table[$field_id] = $this->buildExtraFieldRow($field_id$extra_field);
    }

    $form['fields'] = $table;

    // Custom display settings.     if ($this->entity->getMode() == 'default') {
      // Only show the settings if there is at least one custom display mode.       $display_mode_options = $this->getDisplayModeOptions();
      // Unset default option.       unset($display_mode_options['default']);
      if ($display_mode_options) {
        $form['modes'] = [
          '#type' => 'details',
          '#title' => $this->t('Custom display settings'),
        ];
        // Prepare default values for the 'Custom display settings' checkboxes.         $default = [];
        if ($enabled_displays = array_filter($this->getDisplayStatuses())) {
          $default = array_keys(array_intersect_key($display_mode_options$enabled_displays));
        }
if (isset($display_modes[$entity_type_id])) {
        return $display_modes[$entity_type_id];
      }
    }
    return [];
  }

  /** * {@inheritdoc} */
  public function getViewModeOptions($entity_type) {
    return $this->getDisplayModeOptions('view_mode', $entity_type);
  }

  /** * {@inheritdoc} */
  public function getFormModeOptions($entity_type_id) {
    return $this->getDisplayModeOptions('form_mode', $entity_type_id);
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.