function paragraphs_pack_create_paragraph in Paragraphs pack 7
Creates new paragraph.
Parameters
string $machine_name: A machine name of new paragraph item.
string $name: A human readable name of new paragraph item.
6 calls to paragraphs_pack_create_paragraph()
- ParagraphsPackTestCase::setUp in tests/
paragraphs_pack.test - Set up the test environment.
- paragraphs_pack_content_install in modules/
paragraphs_pack_content/ paragraphs_pack_content.install - Implements hook_install().
- paragraphs_pack_juicebox_install in modules/
paragraphs_pack_juicebox/ paragraphs_pack_juicebox.install - Implements hook_install().
- paragraphs_pack_node_list_install in modules/
paragraphs_pack_node_list/ paragraphs_pack_node_list.install - Implements hook_install().
- paragraphs_pack_taxonomy_term_list_install in modules/
paragraphs_pack_taxonomy_term_list/ paragraphs_pack_taxonomy_term_list.install - Implements hook_install().
File
- ./
paragraphs_pack.module, line 44 - Paragraphs pack primary module file.
Code
function paragraphs_pack_create_paragraph($machine_name, $name) {
$bundle = new stdClass();
// Machine name.
$bundle->bundle = $machine_name;
// Human readable name.
$bundle->name = $name;
$bundle->locked = 1;
$status = paragraphs_bundle_save($bundle);
// Log and notify about the change.
$t = get_t();
$t_args = array(
'%name' => $bundle->name,
);
if ($status == SAVED_NEW) {
drupal_set_message($t('The paragraph bundle %name has been added.', $t_args));
watchdog('paragraphs_pack', 'Added paragraph bundle %name.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/structure/paragraphs'));
}
elseif ($status == SAVED_UPDATED) {
drupal_set_message(t('The paragraph bundle %name has been updated.', $t_args));
}
else {
drupal_set_message($t('The paragraph bundle %name couldn\'t been saved.', $t_args), 'warning');
watchdog('paragraphs_pack', 'The paragraph bundle %name couldn\'t been saved.', $t_args, WATCHDOG_WARNING, l(t('view'), 'admin/structure/paragraphs'));
}
}