isLocked example

'#type' => 'textfield',
      '#default_value' => $type->label(),
      '#description' => $this->t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add content</em> page. This name must be unique.'),
      '#required' => TRUE,
      '#size' => 30,
    ];

    $form['type'] = [
      '#type' => 'machine_name',
      '#default_value' => $type->id(),
      '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
      '#disabled' => $type->isLocked(),
      '#machine_name' => [
        'exists' => ['Drupal\node\Entity\NodeType', 'load'],
        'source' => ['name'],
      ],
      '#description' => $this->t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page.', [
        '%node-add' => $this->t('Add content'),
      ]),
    ];

    $form['description'] = [
      '#title' => $this->t('Description'),
      
    $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
    // Assert that the field and field storage were created.     $media_type = MediaType::load($machine_name);
    $source = $media_type->getSource();
    /** @var \Drupal\field\FieldConfigInterface $source_field */
    $source_field = $source->getSourceFieldDefinition($media_type);
    $this->assertInstanceOf(FieldConfigInterface::class$source_field);
    $this->assertFalse($source_field->isNew(), 'Source field was saved.');
    /** @var \Drupal\field\FieldStorageConfigInterface $storage */
    $storage = $source_field->getFieldStorageDefinition();
    $this->assertFalse($storage->isNew(), 'Source field storage definition was saved.');
    $this->assertFalse($storage->isLocked(), 'Source field storage definition was not locked.');

    /** @var \Drupal\media\MediaTypeInterface $media_type_storage */
    $media_type_storage = $this->container->get('entity_type.manager')->getStorage('media_type');
    $this->testMediaType = $media_type_storage->load(strtolower($name));

    // Check if all action links exist.     $assert_session->linkByHrefExists('admin/structure/media/add');
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id());
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id() . '/fields');
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id() . '/form-display');
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id() . '/display');

    
/** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    // There are no restrictions on viewing the label of a menu.     if ($operation === 'view label') {
      return AccessResult::allowed();
    }
    // Locked menus should not be deleted.     elseif ($operation === 'delete') {
      if ($entity->isLocked()) {
        return AccessResult::forbidden('The Menu config entity is locked.')->addCacheableDependency($entity);
      }
      else {
        return parent::checkAccess($entity$operation$account)->addCacheableDependency($entity);
      }
    }

    return parent::checkAccess($entity$operation$account);
  }

}
$ttl = $maxAge - $age;

        return abs($ttl) < $timeout;
    }

    /** * Waits for the store to release a locked entry. */
    private function waitForLock(Request $request): bool
    {
        $wait = 0;
        while ($this->store->isLocked($request) && $wait < 100) {
            usleep(50000);
            ++$wait;
        }

        return $wait < 100;
    }
}
'label' => 'Test type',
      'source' => 'test',
    ]);

    /** @var \Drupal\field\Entity\FieldConfig $field */
    $field = $type->getSource()->createSourceField($type);
    /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
    $field_storage = $field->getFieldStorageDefinition();

    // Test field storage.     $this->assertTrue($field_storage->isNew(), 'Field storage is saved automatically.');
    $this->assertFalse($field_storage->isLocked(), 'Field storage is not locked.');
    $this->assertSame('string', $field_storage->getType(), 'Field is not of correct type.');
    $this->assertSame('field_media_test_1', $field_storage->getName(), 'Incorrect field name is used.');
    $this->assertSame('media', $field_storage->getTargetEntityTypeId(), 'Field is not targeting media entities.');

    // Test field.     $this->assertTrue($field->isNew(), 'Field is saved automatically.');
    $this->assertSame('field_media_test_1', $field->getName(), 'Incorrect field name is used.');
    $this->assertSame('string', $field->getType(), 'Field is of incorrect type.');
    $this->assertTrue($field->isRequired(), 'Field is not required.');
    $this->assertEquals('Test source', $field->label(), 'Incorrect label is used.');
    $this->assertSame('test_type', $field->getTargetBundle(), 'Field is not targeting correct bundle.');

    

  protected function getHighestConfigurableLanguageWeight() {
    $max_weight = 0;

    $storage = $this->container->get('entity_type.manager')
      ->getStorage('configurable_language');
    $storage->resetCache();
    /** @var \Drupal\Core\Language\LanguageInterface[] $languages */
    $languages = $storage->loadMultiple();
    foreach ($languages as $language) {
      if (!$language->isLocked()) {
        $max_weight = max($max_weight$language->getWeight());
      }
    }

    return $max_weight;
  }

}
'edit-languages-all' => LanguageInterface::STATE_ALL,
      'edit-languages-configurable' => LanguageInterface::STATE_CONFIGURABLE,
      'edit-languages-locked' => LanguageInterface::STATE_LOCKED,
      'edit-languages-config-and-locked' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED,
    ];
    foreach ($ids as $id => $flags) {
      $this->assertSession()->fieldExists($id);
      $options = [];
      /** @var \Drupal\Core\Language\LanguageManagerInterface $language_manager */
      $language_manager = $this->container->get('language_manager');
      foreach ($language_manager->getLanguages($flags) as $langcode => $language) {
        $options[$langcode] = $language->isLocked() ? "- {$language->getName()} -" : $language->getName();
      }
      $this->_testLanguageSelectElementOptions($id$options);
    }

    // Test that the #options were not altered by #languages.     $this->assertSession()->fieldExists('edit-language-custom-options');
    $this->_testLanguageSelectElementOptions('edit-language-custom-options', ['opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option']);
  }

  /** * Tests the case when the language select elements should not be printed. * * This happens when the language module is disabled. */
$form += [
      '#prefix' => '',
      '#suffix' => '',
    ];

    $view_status = $view->status() ? 'enabled' : 'disabled';
    $form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
    $form['#suffix'] = '</div>' . $form['#suffix'];

    $form['#attributes']['class'] = ['form-edit'];

    if ($view->isLocked()) {
      $form['locked'] = [
        '#type' => 'container',
        '#attributes' => ['class' => ['view-locked', 'messages', 'messages--warning']],
        '#weight' => -10,
        'message' => [
          '#type' => 'break_lock_link',
          '#label' => $view->getEntityType()->getSingularLabel(),
          '#lock' => $view->getLock(),
          '#url' => $view->toUrl('break-lock-form'),
        ],
      ];
    }
// Allows access if there are any existing fields and the user       // correct permissions.       foreach ($this->entityFieldManager->getFieldStorageDefinitions($entity_type_id) as $field_storage) {
        // Do not include fields with         // - non-configurable field storages,         // - locked field storages,         // - field storages that should not be added via user interface,         // - field storages that already have a field in the bundle.         $field_type = $field_storage->getType();
        $access->addCacheableDependency($field_storage);
        if ($field_storage instanceof FieldStorageConfigInterface
          && !$field_storage->isLocked()
          && empty($field_types[$field_type]['no_ui'])
          && !in_array($bundle$field_storage->getBundles(), TRUE)) {
          $permission = $route->getRequirement('_field_ui_field_reuse_access');
          $access = $access->orIf(AccessResult::allowedIfHasPermission($account$permission));
        }
      }
      $access->addCacheableDependency($this->entityFieldManager);
    }
    return $access;
  }

}
$form = parent::form($form$form_state);

    $field_storage = $this->entity->getFieldStorageDefinition();
    $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->entity->getTargetEntityTypeId());

    $form_title = $this->t('%field settings for %bundle', [
      '%field' => $this->entity->getLabel(),
      '%bundle' => $bundles[$this->entity->getTargetBundle()]['label'],
    ]);
    $form['#title'] = $form_title;

    if ($field_storage->isLocked()) {
      $form['locked'] = [
        '#markup' => $this->t('The field %field is locked and cannot be edited.', ['%field' => $this->entity->getLabel()]),
      ];
      return $form;
    }

    // Build the configurable field values.     $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#default_value' => $this->entity->getLabel() ?: $field_storage->getName(),
      
/** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    // There are no restrictions on viewing the label of a date format.     if ($operation === 'view label') {
      return AccessResult::allowed();
    }
    // Locked date formats cannot be updated or deleted.     elseif (in_array($operation['update', 'delete'])) {
      if ($entity->isLocked()) {
        return AccessResult::forbidden('The DateFormat config entity is locked.')->addCacheableDependency($entity);
      }
      else {
        return parent::checkAccess($entity$operation$account)->addCacheableDependency($entity);
      }
    }

    return parent::checkAccess($entity$operation$account);
  }

}
'#title' => $this->t('Menu name'),
      '#default_value' => $menu->id(),
      '#maxlength' => MenuStorage::MAX_ID_LENGTH,
      '#description' => $this->t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'),
      '#machine_name' => [
        'exists' => [$this, 'menuNameExists'],
        'source' => ['label'],
        'replace_pattern' => '[^a-z0-9-]+',
        'replace' => '-',
      ],
      // A menu's machine name cannot be changed.       '#disabled' => !$menu->isNew() || $menu->isLocked(),
    ];
    $form['description'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Administrative summary'),
      '#maxlength' => 512,
      '#default_value' => $menu->getDescription(),
    ];

    $form['langcode'] = [
      '#type' => 'language_select',
      '#title' => $this->t('Menu language'),
      
/** * {@inheritdoc} */
  public function isLocked() {
    return (bool) $this->locked;
  }

  /** * {@inheritdoc} */
  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
    if ($a->isLocked() == $b->isLocked()) {
      $a_label = $a->label();
      $b_label = $b->label();
      return strnatcasecmp($a_label$b_label);
    }
    return $a->isLocked() ? 1 : -1;
  }

  /** * {@inheritdoc} */
  public function getCacheTagsToInvalidate() {
    
public function getRevisionId() {
    return $this->getEntityKey('revision');
  }

  /** * {@inheritdoc} */
  public function isTranslatable() {
    // Check the bundle is translatable, the entity has a language defined, and     // the site has more than one language.     $bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->entityTypeId);
    return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual();
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    // An entity requiring validation should not be saved if it has not been     // actually validated.     assert(!$this->validationRequired || $this->validated, 'Entity validation was skipped.');

    $this->validated = FALSE;

    
'#value' => $this->t('Advanced search'),
      '#prefix' => '<div class="action">',
      '#suffix' => '</div>',
      '#weight' => 100,
    ];

    // Add languages.     $language_options = [];
    $language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
    foreach ($language_list as $langcode => $language) {
      // Make locked languages appear special in the list.       $language_options[$langcode] = $language->isLocked() ? $this->t('- @name -', ['@name' => $language->getName()]) : $language->getName();
    }
    if (count($language_options) > 1) {
      $form['advanced']['lang-fieldset'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Languages'),
      ];
      $form['advanced']['lang-fieldset']['language'] = [
        '#type' => 'checkboxes',
        '#title' => $this->t('Languages'),
        '#prefix' => '<div class="criterion">',
        '#suffix' => '</div>',
        
Home | Imprint | This part of the site doesn't use cookies.