View source
<?php
function paragraphs_items_page_view($paragraphs_items) {
$field_paragraphs = paragraphs_field_get_entity($paragraphs_items);
if (empty($field_paragraphs)) {
return;
}
return $field_paragraphs
->view('full');
}
function paragraphs_items_form($form, &$form_state, $paragraphs_items) {
$form['actions'] = array(
'#type' => 'actions',
'#weight' => 50,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 5,
);
return $form;
}
function paragraphs_items_form_validate($form, &$form_state) {
}
function paragraphs_items_form_submit_build_field_collection($form, $form_state) {
return $form_state;
}
function paragraphs_items_form_submit($form, &$form_state) {
}
function paragraphs_items_delete_confirm($form, &$form_state, $paragraphs_items) {
$form_state += array(
'paragraphs_items' => $paragraphs_items,
);
return confirm_form($form, t('Are you sure you want to delete %label?', array(
'%label' => $paragraphs_items
->label(),
)), $paragraphs_items
->path(), t('This action cannot be undone.'), t('Delete'), t('Cancel'));
}
function paragraphs_items_delete_confirm_submit($form, &$form_state) {
$paragraphs_items = $form_state['paragraphs_items'];
entity_delete('paragraphs_items', $paragraphs_items->item_id);
drupal_set_message(t('%label has been deleted.', array(
'%label' => drupal_ucfirst($paragraphs_items
->label()),
)));
$form_state['redirect'] = '<front>';
}
function paragraphs_items_add($field_name, $entity_type, $entity_id, $revision_id = NULL, $langcode = NULL) {
$info = entity_get_info();
if (!isset($info[$entity_type])) {
return MENU_NOT_FOUND;
}
$result = entity_load($entity_type, array(
$entity_id,
));
$entity = reset($result);
if (!$entity) {
return MENU_NOT_FOUND;
}
list($id, $rev_id, $bundle) = entity_extract_ids($entity_type, $entity);
$instance = field_info_instance($entity_type, $field_name, $bundle);
if (!$instance) {
return MENU_NOT_FOUND;
}
$field = field_info_field($field_name);
$langcode = !empty($field['translatable']) ? entity_language($entity_type, $entity) : LANGUAGE_NONE;
if (!($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || !isset($entity->{$field_name}[$langcode]) || count($entity->{$field_name}[$langcode]) < $field['cardinality'])) {
drupal_set_message(t('Too many items.'), 'error');
return '';
}
$paragraphs_items = entity_create('paragraphs_items', array(
'field_name' => $field_name,
));
$paragraphs_items
->setHostEntity($entity_type, $entity, $langcode, FALSE);
$label = $paragraphs_items
->translatedInstanceLabel();
$title = $field['cardinality'] == 1 ? $label : t('Add new !instance_label', array(
'!instance_label' => $label,
));
drupal_set_title($title);
global $user;
$account = user_load($user->uid);
if (!entity_access('create', 'paragraphs_items', $paragraphs_items, $account)) {
return MENU_ACCESS_DENIED;
}
return drupal_get_form('paragraphs_items_form', $paragraphs_items);
}