"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php" (26 Nov 2020, 6094 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "EntityDisplayRepositoryInterface.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\Core\Entity;
    4 
    5 /**
    6  * Provides an interface for an entity display repository.
    7  */
    8 interface EntityDisplayRepositoryInterface {
    9 
   10   /**
   11    * The default display mode ID.
   12    *
   13    * @var string
   14    */
   15   const DEFAULT_DISPLAY_MODE = 'default';
   16 
   17   /**
   18    * Gets the entity view mode info for all entity types.
   19    *
   20    * @return array
   21    *   The view mode info for all entity types.
   22    */
   23   public function getAllViewModes();
   24 
   25   /**
   26    * Gets the entity view mode info for a specific entity type.
   27    *
   28    * @param string $entity_type_id
   29    *   The entity type whose view mode info should be returned.
   30    *
   31    * @return array
   32    *   The view mode info for a specific entity type.
   33    */
   34   public function getViewModes($entity_type_id);
   35 
   36   /**
   37    * Gets the entity form mode info for all entity types.
   38    *
   39    * @return array
   40    *   The form mode info for all entity types.
   41    */
   42   public function getAllFormModes();
   43 
   44   /**
   45    * Gets the entity form mode info for a specific entity type.
   46    *
   47    * @param string $entity_type_id
   48    *   The entity type whose form mode info should be returned.
   49    *
   50    * @return array
   51    *   The form mode info for a specific entity type.
   52    */
   53   public function getFormModes($entity_type_id);
   54 
   55   /**
   56    * Gets an array of view mode options.
   57    *
   58    * @param string $entity_type_id
   59    *   The entity type whose view mode options should be returned.
   60    *
   61    * @return array
   62    *   An array of view mode labels, keyed by the display mode ID.
   63    */
   64   public function getViewModeOptions($entity_type_id);
   65 
   66   /**
   67    * Gets an array of form mode options.
   68    *
   69    * @param string $entity_type_id
   70    *   The entity type whose form mode options should be returned.
   71    *
   72    * @return array
   73    *   An array of form mode labels, keyed by the display mode ID.
   74    */
   75   public function getFormModeOptions($entity_type_id);
   76 
   77   /**
   78    * Returns an array of enabled view mode options by bundle.
   79    *
   80    * @param string $entity_type_id
   81    *   The entity type whose view mode options should be returned.
   82    * @param string $bundle
   83    *   The name of the bundle.
   84    *
   85    * @return array
   86    *   An array of view mode labels, keyed by the display mode ID.
   87    */
   88   public function getViewModeOptionsByBundle($entity_type_id, $bundle);
   89 
   90   /**
   91    * Returns an array of enabled form mode options by bundle.
   92    *
   93    * @param string $entity_type_id
   94    *   The entity type whose form mode options should be returned.
   95    * @param string $bundle
   96    *   The name of the bundle.
   97    *
   98    * @return array
   99    *   An array of form mode labels, keyed by the display mode ID.
  100    */
  101   public function getFormModeOptionsByBundle($entity_type_id, $bundle);
  102 
  103   /**
  104    * Clears the gathered display mode info.
  105    *
  106    * @return $this
  107    */
  108   public function clearDisplayModeInfo();
  109 
  110   /**
  111    * Returns the entity view display associated with a bundle and view mode.
  112    *
  113    * Use this function when assigning suggested display options for a component
  114    * in a given view mode. Note that they will only be actually used at render
  115    * time if the view mode itself is configured to use dedicated display
  116    * settings for the bundle; if not, the 'default' display is used instead.
  117    *
  118    * The function reads the entity view display from the current configuration,
  119    * or returns a ready-to-use empty one if configuration entry exists yet for
  120    * this bundle and view mode. This streamlines manipulation of display objects
  121    * by always returning a consistent object that reflects the current state of
  122    * the configuration.
  123    *
  124    * Example usage:
  125    * - Set the 'body' field to be displayed and the 'field_image' field to be
  126    *   hidden on article nodes in the 'default' display.
  127    * @code
  128    * \Drupal::service('entity_display.repository')
  129    *   ->getViewDisplay('node', 'article', 'default')
  130    *   ->setComponent('body', array(
  131    *     'type' => 'text_summary_or_trimmed',
  132    *     'settings' => array('trim_length' => '200')
  133    *     'weight' => 1,
  134    *   ))
  135    *   ->removeComponent('field_image')
  136    *   ->save();
  137    * @endcode
  138    *
  139    * @param string $entity_type
  140    *   The entity type.
  141    * @param string $bundle
  142    *   The bundle.
  143    * @param string $view_mode
  144    *   (optional) The view mode. Defaults to self::DEFAULT_DISPLAY_MODE.
  145    *
  146    * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface
  147    *   The entity view display associated with the view mode.
  148    */
  149   public function getViewDisplay($entity_type, $bundle, $view_mode = self::DEFAULT_DISPLAY_MODE);
  150 
  151   /**
  152    * Returns the entity form display associated with a bundle and form mode.
  153    *
  154    * The function reads the entity form display object from the current
  155    * configuration, or returns a ready-to-use empty one if no configuration
  156    * entry exists yet for this bundle and form mode. This streamlines
  157    * manipulation of entity form displays by always returning a consistent
  158    * object that reflects the current state of the configuration.
  159    *
  160    * Example usage:
  161    * - Set the 'body' field to be displayed with the
  162    *   'text_textarea_with_summary' widget and the 'field_image' field to be
  163    *   hidden on article nodes in the 'default' form mode.
  164    * @code
  165    * \Drupal::service('entity_display.repository')
  166    *   ->getFormDisplay('node', 'article', 'default')
  167    *   ->setComponent('body', array(
  168    *     'type' => 'text_textarea_with_summary',
  169    *     'weight' => 1,
  170    *   ))
  171    *   ->setComponent('field_image', array(
  172    *     'region' => 'hidden',
  173    *   ))
  174    *   ->save();
  175    * @endcode
  176    *
  177    * @param string $entity_type
  178    *   The entity type.
  179    * @param string $bundle
  180    *   The bundle.
  181    * @param string $form_mode
  182    *   (optional) The form mode. Defaults to self::DEFAULT_DISPLAY_MODE.
  183    *
  184    * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
  185    *   The entity form display associated with the given form mode.
  186    *
  187    * @see \Drupal\Core\Entity\EntityStorageInterface::create()
  188    * @see \Drupal\Core\Entity\EntityStorageInterface::load()
  189    */
  190   public function getFormDisplay($entity_type, $bundle, $form_mode = self::DEFAULT_DISPLAY_MODE);
  191 
  192 }