getFormModeOptions example

/** * Rebuild displays for single Entity Type. * * @param string $entity_type_id * The entity type machine name. * @param string $bundle * The bundle we need to rebuild. */
  public function rebuildEntityTypeDisplays($entity_type_id$bundle) {
    // Get the displays.     $view_modes = $this->entityDisplayRepository->getViewModeOptions($entity_type_id);
    $form_modes = $this->entityDisplayRepository->getFormModeOptions($entity_type_id);

    // Save view mode displays.     $view_mode_ids = array_map(function D$view_mode) use ($entity_type_id$bundle) {
      return "$entity_type_id.$bundle.$view_mode";
    }array_keys($view_modes));
    foreach ($this->entityTypeManager->getStorage('entity_view_display')->loadMultiple($view_mode_ids) as $display) {
      $display->save();
    }
    // Save form mode displays.     $form_mode_ids = array_map(function D$form_mode) use ($entity_type_id$bundle) {
      return "$entity_type_id.$bundle.$form_mode";
    },
/** * {@inheritdoc} */
  protected function getDisplayModes() {
    return $this->entityDisplayRepository->getFormModes($this->entity->getTargetEntityTypeId());
  }

  /** * {@inheritdoc} */
  protected function getDisplayModeOptions() {
    return $this->entityDisplayRepository->getFormModeOptions($this->entity->getTargetEntityTypeId());
  }

  /** * {@inheritdoc} */
  protected function getDisplayModesLink() {
    return [
      '#type' => 'link',
      '#title' => $this->t('Manage form modes'),
      '#url' => Url::fromRoute('entity.entity_form_mode.collection'),
    ];
  }
Home | Imprint | This part of the site doesn't use cookies.