getDisplayModes example

    // was being edited, update the new incoming settings when rebuilding the     // entity, just as if the subform's "Update" button had been submitted.     if ($edit_field = $form_state->get('plugin_settings_edit')) {
      $form_state->set('plugin_settings_update', $edit_field);
    }

    parent::submitForm($form$form_state);
    $form_values = $form_state->getValues();

    // Handle the 'display modes' checkboxes if present.     if ($this->entity->getMode() == 'default' && !empty($form_values['display_modes_custom'])) {
      $display_modes = $this->getDisplayModes();
      $current_statuses = $this->getDisplayStatuses();

      $statuses = [];
      foreach ($form_values['display_modes_custom'] as $mode => $value) {
        if (!empty($value) && empty($current_statuses[$mode])) {
          // If no display exists for the newly enabled view mode, initialize           // it with those from the 'default' view mode, which were used so           // far.           if (!$this->entityTypeManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.' . $mode)) {
            $display = $this->getEntityDisplay($this->entity->getTargetEntityTypeId()$this->entity->getTargetBundle(), 'default')->createCopy($mode);
            $display->save();
          }
Home | Imprint | This part of the site doesn't use cookies.