shouldCreateNewRevision example

$this->updateEntityField($resource_type$parsed_entity$destination$field_name);
      return $destination;
    }$entity);

    static::validate($entity$field_names);

    // Set revision data details for revisionable entities.     if ($entity->getEntityType()->isRevisionable()) {
      if ($bundle_entity_type = $entity->getEntityType()->getBundleEntityType()) {
        $bundle_entity = $this->entityTypeManager->getStorage($bundle_entity_type)->load($entity->bundle());
        if ($bundle_entity instanceof RevisionableEntityBundleInterface) {
          $entity->setNewRevision($bundle_entity->shouldCreateNewRevision());
        }
      }
      if ($entity instanceof RevisionLogInterface && $entity->isNewRevision()) {
        $entity->setRevisionUserId($this->user->id());
        $entity->setRevisionCreationTime($this->time->getRequestTime());
      }
    }

    $entity->save();
    $primary_data = new ResourceObjectData([ResourceObject::createFromEntity($resource_type$entity)], 1);
    return $this->buildWrappedResponse($primary_data$request$this->getIncludes($request$primary_data));
  }


  /** * Prepares workflow options to be used in the 'checkboxes' form element. * * @return array * Array of options ready to be used in #options. */
  protected function getWorkflowOptions() {
    $workflow_options = [
      'status' => $this->entity->getStatus(),
      'new_revision' => $this->entity->shouldCreateNewRevision(),
      'queue_thumbnail_downloads' => $this->entity->thumbnailDownloadsAreQueued(),
    ];
    // Prepare workflow options to be used for 'checkboxes' form element.     $keys = array_keys(array_filter($workflow_options));
    return array_combine($keys$keys);
  }

  /** * Gets subform state for the media source configuration subform. * * @param array $form * Full form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * Parent form state. * * @return \Drupal\Core\Form\SubformStateInterface * Sub-form state for the media source configuration form. */
$assert_session->fieldValueEquals('Attribute 2', MediaSourceInterface::METADATA_FIELD_EMPTY);

    /** @var \Drupal\media\MediaTypeInterface $loaded_media_type */
    $loaded_media_type = $this->container->get('entity_type.manager')
      ->getStorage('media_type')
      ->load($this->testMediaType->id());
    $this->assertSame($loaded_media_type->id()$this->testMediaType->id());
    $this->assertSame($loaded_media_type->label()$new_name);
    $this->assertSame($loaded_media_type->getDescription()$new_description);
    $this->assertSame($loaded_media_type->getSource()->getPluginId(), 'test');
    $this->assertSame($loaded_media_type->getSource()->getConfiguration()['test_config_value'], 'This is new config value.');
    $this->assertTrue($loaded_media_type->shouldCreateNewRevision());
    $this->assertTrue($loaded_media_type->thumbnailDownloadsAreQueued());
    $this->assertFalse($loaded_media_type->getStatus());
    $this->assertSame($loaded_media_type->getFieldMap()['attribute_1' => 'name']);

    // We need to clear the statically cached field definitions to account for     // fields that have been created by API calls in this test, since they exist     // in a separate memory space from the web server.     $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();

    // Test that a media item being created with default status to "FALSE",     // will be created unpublished.
'#description' => $this->t('This text will be displayed at the top of the page when creating or editing content of this type.'),
    ];
    $form['workflow'] = [
      '#type' => 'details',
      '#title' => $this->t('Publishing options'),
      '#group' => 'additional_settings',
    ];
    $workflow_options = [
      'status' => $node->status->value,
      'promote' => $node->promote->value,
      'sticky' => $node->sticky->value,
      'revision' => $type->shouldCreateNewRevision(),
    ];
    // Prepare workflow options to be used for 'checkboxes' form element.     $keys = array_keys(array_filter($workflow_options));
    $workflow_options = array_combine($keys$keys);
    $form['workflow']['options'] = [
      '#type' => 'checkboxes',
      '#title' => $this->t('Default options'),
      '#default_value' => $workflow_options,
      '#options' => [
        'status' => $this->t('Published'),
        'promote' => $this->t('Promoted to front page'),
        

  protected function assertEntity(string $id, string $label, string $description, string $help, bool $display_submitted, bool $new_revision, ?array $expected_available_menus, ?string $expected_parent, ?string $body_label = NULL): void {
    /** @var \Drupal\node\NodeTypeInterface $entity */
    $entity = NodeType::load($id);
    $this->assertInstanceOf(NodeTypeInterface::class$entity);
    $this->assertSame($label$entity->label());
    $this->assertSame($description$entity->getDescription());

    $this->assertSame($help$entity->getHelp());

    $this->assertSame($display_submitted$entity->displaySubmitted(), 'Submission info is displayed');
    $this->assertSame($new_revision$entity->shouldCreateNewRevision(), 'Is a new revision');

    if ($body_label) {
      /** @var \Drupal\field\FieldConfigInterface $body */
      $body = FieldConfig::load('node.' . $id . '.body');
      $this->assertInstanceOf(FieldConfigInterface::class$body);
      $this->assertSame($body_label$body->label());
    }

    $this->assertSame($expected_available_menus$entity->getThirdPartySetting('menu_ui', 'available_menus'));
    $this->assertSame($expected_parent$entity->getThirdPartySetting('menu_ui', 'parent'));
  }

  
protected function createContentTypeFromUi($content_type_name$content_type_id$moderated = FALSE, $workflow_id = 'editorial') {
    $this->drupalGet('admin/structure/types');
    $this->clickLink('Add content type');

    $edit = [
      'name' => $content_type_name,
      'type' => $content_type_id,
    ];
    $this->submitForm($edit, 'Save content type');

    // Check the content type has been set to create new revisions.     $this->assertTrue(NodeType::load($content_type_id)->shouldCreateNewRevision());

    if ($moderated) {
      $this->enableModerationThroughUi($content_type_id$workflow_id);
    }
  }

  /** * Enable moderation for a specified content type, using the UI. * * @param string $content_type_id * Machine name. * @param string $workflow_id * The workflow to attach to the bundle. */
$form['description'] = [
      '#type' => 'textarea',
      '#default_value' => $block_type->getDescription(),
      '#description' => $this->t('Enter a description for this block type.'),
      '#title' => $this->t('Description'),
    ];

    $form['revision'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Create new revision'),
      '#default_value' => $block_type->shouldCreateNewRevision(),
      '#description' => $this->t('Create a new revision by default for this block type.'),
    ];

    if ($this->moduleHandler->moduleExists('language')) {
      $form['language'] = [
        '#type' => 'details',
        '#title' => $this->t('Language settings'),
        '#group' => 'additional_settings',
      ];

      $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
      
    $read_only_fields = ['revision_timestamp', 'revision_uid'];
    if ($operation == 'edit' && in_array($field_definition->getName()$read_only_fields, TRUE)) {
      return AccessResult::forbidden();
    }

    // Users have access to the revision_log field either if they have     // administrative permissions or if the new revision option is enabled.     if ($operation == 'edit' && $field_definition->getName() == 'revision_log') {
      if ($account->hasPermission('administer nodes')) {
        return AccessResult::allowed()->cachePerPermissions();
      }
      return AccessResult::allowedIf($items->getEntity()->type->entity->shouldCreateNewRevision())->cachePerPermissions();
    }
    return parent::checkFieldAccess($operation$field_definition$account$items);
  }

  /** * {@inheritdoc} */
  public function acquireGrants(NodeInterface $node) {
    $grants = $this->moduleHandler->invokeAll('node_access_records', [$node]);
    // Let modules alter the grants.     $this->moduleHandler->alter('node_access_records', $grants$node);
    
/** * Should new revisions created on default. * * @return bool * New revision on default. */
  protected function getNewRevisionDefault() {
    $new_revision_default = FALSE;
    $bundle_entity = $this->getBundleEntity();
    if ($bundle_entity instanceof RevisionableEntityBundleInterface) {
      // Always use the default revision setting.       $new_revision_default = $bundle_entity->shouldCreateNewRevision();
    }
    return $new_revision_default;
  }

  /** * Checks whether the revision form fields should be added to the form. * * @return bool * TRUE if the form field should be added, FALSE otherwise. */
  protected function showRevisionUi() {
    


  /** * Tests Drupal 6 node type to Drupal 8 migration. */
  public function testNodeType() {
    $id_map = $this->getMigration('d6_node_type')->getIdMap();
    // Test the test_page content type.     $node_type_page = NodeType::load('test_page');
    $this->assertSame('test_page', $node_type_page->id(), 'Node type test_page loaded');
    $this->assertTrue($node_type_page->displaySubmitted());
    $this->assertFalse($node_type_page->shouldCreateNewRevision());
    $this->assertSame(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
    $this->assertSame($id_map->lookupDestinationIds(['test_page'])[['test_page']]);

    // Test we have a body field.     $field = FieldConfig::loadByName('node', 'test_page', 'body');
    $this->assertSame('This is the body field label', $field->getLabel(), 'Body field was found.');

    // Test default menus.     $expected_available_menus = ['navigation'];
    $this->assertSame($expected_available_menus$node_type_page->getThirdPartySetting('menu_ui', 'available_menus'));
    $expected_parent = 'navigation:';
    
Home | Imprint | This part of the site doesn't use cookies.