function block_content_test_block_content_insert

Same name and namespace in other branches
  1. 10 core/modules/block_content/tests/modules/block_content_test/block_content_test.module \block_content_test_block_content_insert()
  2. 8.9.x core/modules/block_content/tests/modules/block_content_test/block_content_test.module \block_content_test_block_content_insert()

Implements hook_block_content_insert().

This tests saving a block_content on block_content insert.

See also

\Drupal\block_content\Tests\BlockContentSaveTest::testBlockContentSaveOnInsert()

File

core/modules/block_content/tests/modules/block_content_test/block_content_test.module, line 59

Code

function block_content_test_block_content_insert(BlockContent $block_content) {
  // Set the block_content title to the block_content ID and save.
  if ($block_content->label() == 'new') {
    $block_content->setInfo('BlockContent ' . $block_content->id());
    $block_content->setNewRevision(FALSE);
    $block_content->save();
  }
  if ($block_content->label() == 'fail_creation') {
    throw new Exception('Test exception for rollback.');
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.