isLayoutBuilderEnabled example

// Set $entityFieldManager before calling the parent constructor because the     // constructor will call init() which then calls setComponent() which needs     // $entityFieldManager.     $this->entityFieldManager = \Drupal::service('entity_field.manager');
    parent::__construct($values$entity_type);
  }

  /** * {@inheritdoc} */
  public function isOverridable() {
    return $this->isLayoutBuilderEnabled() && $this->getThirdPartySetting('layout_builder', 'allow_custom', FALSE);
  }

  /** * {@inheritdoc} */
  public function setOverridable($overridable = TRUE) {
    $this->setThirdPartySetting('layout_builder', 'allow_custom', $overridable);
    // Enable Layout Builder if it's not already enabled and overriding.     if ($overridable && !$this->isLayoutBuilderEnabled()) {
      $this->enableLayoutBuilder();
    }
    

  public function setThirdPartySetting($module$key$value) {
    $this->getDisplay()->setThirdPartySetting($module$key$value);
    return $this;
  }

  /** * {@inheritdoc} */
  public function isLayoutBuilderEnabled() {
    return $this->getDisplay()->isLayoutBuilderEnabled();
  }

  /** * {@inheritdoc} */
  public function enableLayoutBuilder() {
    $this->getDisplay()->enableLayoutBuilder();
    return $this;
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    // Remove the Layout Builder field from the list.     $form['#fields'] = array_diff($form['#fields'][OverridesSectionStorage::FIELD_NAME]);
    unset($form['fields'][OverridesSectionStorage::FIELD_NAME]);

    $is_enabled = $this->entity->isLayoutBuilderEnabled();
    if ($is_enabled) {
      // Hide the table of fields.       $form['fields']['#access'] = FALSE;
      $form['#fields'] = [];
      $form['#extra'] = [];
    }

    $form['manage_layout'] = [
      '#type' => 'link',
      '#title' => $this->t('Manage layout'),
      '#weight' => -10,
      
$display = LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => $view_mode,
      'status' => TRUE,
      'third_party_settings' => [
        'layout_builder' => [
          'enabled' => $enabled,
        ],
      ],
    ]);
    $result = $display->isLayoutBuilderEnabled();
    $this->assertSame($expected$result);
  }

  /** * Provides test data for ::testIsLayoutBuilderEnabled(). */
  public function providerTestIsLayoutBuilderEnabled() {
    $data = [];
    $data['default enabled'] = [TRUE, 'default', TRUE];
    $data['default disabled'] = [FALSE, 'default', FALSE];
    $data['full enabled'] = [TRUE, 'full', TRUE];
    


/** * Update timestamp formatter settings for Layout Builder fields. */
function layout_builder_post_update_timestamp_formatter(array &$sandbox = NULL): void {
  /** @var \Drupal\Core\Field\FormatterPluginManager $field_formatter_manager */
  $field_formatter_manager = \Drupal::service('plugin.manager.field.formatter');

  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'entity_view_display', function DEntityViewDisplayInterface $entity_view_display) use ($field_formatter_manager): bool {
    $update = FALSE;
    if ($entity_view_display instanceof LayoutEntityDisplayInterface && $entity_view_display->isLayoutBuilderEnabled()) {
      foreach ($entity_view_display->getSections() as $section) {
        foreach ($section->getComponents() as $component) {
          if (str_starts_with($component->getPluginId(), 'field_block:')) {
            $configuration = $component->get('configuration');
            $formatter =& $configuration['formatter'];
            if ($formatter && isset($formatter['type'])) {
              $plugin_definition = $field_formatter_manager->getDefinition($formatter['type'], FALSE);
              // Check also potential plugins extending TimestampFormatter.               if ($plugin_definition && is_a($plugin_definition['class'], TimestampFormatter::class, TRUE)) {
                if (!isset($formatter['settings']['tooltip']) || !isset($formatter['settings']['time_diff'])) {
                  $update = TRUE;
                  
Home | Imprint | This part of the site doesn't use cookies.