/** * {@inheritdoc} */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); if (!$update && !$this->isSyncing()) { block_content_add_body_field($this->id); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create the "basic" block type. $bundle = BlockContentType::create(['id' => 'basic', 'label' => 'basic', 'revision' => FALSE]); $bundle->save(); // Add the body field to it. block_content_add_body_field($bundle->id()); }
/** * {@inheritdoc} */ protected function createEntity() { $block_content_type = entity_create('block_content_type', array('id' => 'basic', 'label' => 'basic', 'revision' => FALSE)); $block_content_type->save(); block_content_add_body_field($block_content_type->id()); // Create a "Llama" custom block. $block_content = entity_create('block_content', array('info' => 'Llama', 'type' => 'basic', 'body' => array('value' => 'The name "llama" was adopted by European settlers from native Peruvians.', 'format' => 'plain_text'))); $block_content->save(); return $block_content; }
/** * {@inheritdoc} */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); if (!$update && !$this->isSyncing()) { entity_invoke_bundle_hook('create', 'block_content', $this->id()); if (!$this->isSyncing()) { block_content_add_body_field($this->id); } } elseif ($this->getOriginalId() != $this->id) { entity_invoke_bundle_hook('rename', 'block_content', $this->getOriginalId(), $this->id); } }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $block_type = $this->entity; $status = $block_type->save(); $edit_link = $this->entity->link($this->t('Edit')); $logger = $this->logger('block_content'); if ($status == SAVED_UPDATED) { drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); $logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link)); } else { block_content_add_body_field($block_type->id()); drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label()))); $logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link)); } $form_state->setRedirectUrl($this->entity->urlInfo('collection')); }
/** * Creates a custom block type (bundle). * * @param array $values * An array of settings to change from the defaults. * * @return \Drupal\block_content\Entity\BlockContentType * Created custom block type. */ protected function createBlockContentType(array $values = array()) { // Find a non-existent random type name. if (!isset($values['id'])) { do { $id = strtolower($this->randomMachineName(8)); } while (BlockContentType::load($id)); } else { $id = $values['id']; } $values += array('id' => $id, 'label' => $id, 'revision' => FALSE); $bundle = BlockContentType::create($values); $status = $bundle->save(); block_content_add_body_field($bundle->id()); $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content type %bundle.', array('%bundle' => $bundle->id()))); return $bundle; }
/** * Creates a custom block type (bundle). * * @param string $label * The block type label. * @param bool $create_body * Whether or not to create the body field * * @return \Drupal\block_content\Entity\BlockContentType * Created custom block type. */ protected function createBlockContentType($label, $create_body = FALSE) { $bundle = BlockContentType::create(array('id' => $label, 'label' => $label, 'revision' => FALSE)); $bundle->save(); if ($create_body) { block_content_add_body_field($bundle->id()); } return $bundle; }