View source
<?php
class PanelizerEntityParagraphsItem extends PanelizerEntityDefault {
public $supports_revisions = TRUE;
public $entity_admin_root = 'admin/structure/paragraphs/%paragraphs_panelizer_bundle_name';
public $entity_admin_bundle = 3;
public $views_table = 'paragraphs_item';
public function entity_access($op, $entity) {
return entity_access($op, $this->entity_type, $entity);
}
public function entity_save($entity) {
entity_save($this->entity_type, $entity);
}
public function entity_identifier($entity) {
return t('This paragraph item');
}
public function entity_bundle_label() {
return t('Paragraph item');
}
public function entity_allows_revisions($entity) {
$retval = array();
$retval[0] = TRUE;
$retval[1] = $this
->entity_access(!empty($entity->is_new) ? 'create' : 'update', $entity);
return $retval;
}
public function get_default_display($bundle, $view_mode) {
return parent::get_default_display($bundle, $view_mode);
}
public function add_bundle_setting_form(&$form, &$form_state, $bundle, $type_location) {
parent::add_bundle_setting_form($form, $form_state, $bundle, $type_location);
$submit_handler = 'panelizer_entity_default_bundle_form_submit';
if (($index = array_search($submit_handler, $form['#submit'])) !== FALSE) {
unset($form['#submit'][$index]);
$form['#submit'][] = $submit_handler;
}
}
public function hook_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'paragraphs_admin_bundle_form') {
if (isset($form['#paragraphs_bundle'])) {
$bundle = $form['#paragraphs_bundle']->bundle;
$form['panelizer_bundle'] = array(
'#type' => 'value',
'#value' => $bundle,
);
$this
->add_bundle_setting_form($form, $form_state, $bundle, array(
empty($form_state['values']['locked']) && empty($bundle) ? 'bundle' : 'panelizer_bundle',
));
}
}
}
public function hook_page_alter(&$page) {
if (current_path() == 'admin/structure/paragraphs') {
if (!empty($page['content']['system_main']['paragraphs_bundle_table'])) {
$table =& $page['content']['system_main']['paragraphs_bundle_table'];
$operationsCol = end($table['#header']);
if (!empty($operationsCol['colspan'])) {
$operationsColKey = key($table['#header']);
$table['#header'][$operationsColKey]['colspan']++;
}
foreach ($table['#rows'] as $bundle => &$row) {
$bundle_url_str = str_replace('_', '-', $bundle);
if ($this
->is_panelized($bundle) && panelizer_administer_entity_bundle($this, $bundle)) {
$row[] = array(
'data' => l(t('panelizer'), 'admin/structure/paragraphs/' . $bundle_url_str . '/panelizer'),
);
}
else {
$row[] = array(
'data' => '',
);
}
}
}
}
}
public function hook_field_attach_form($entity, &$form, &$form_state, $langcode) {
parent::hook_field_attach_form($entity, $form, $form_state, $langcode);
if (isset($form['panelizer']['#group'])) {
$form['panelizer']['#group'] = NULL;
}
}
public function hook_field_attach_submit($entity, &$form, &$form_state) {
if (!empty($form_state['panelizer has choice'])) {
list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) {
if (isset($form['#parents']) && drupal_array_nested_key_exists($form_state['values'], $form['#parents'])) {
$values = drupal_array_get_nested_value($form_state['values'], $form['#parents']);
if (isset($values['panelizer'][$view_mode]['name'])) {
$entity->panelizer[$view_mode] = clone $this
->get_default_panelizer_object($bundle . '.' . $view_mode, $values['panelizer'][$view_mode]['name']);
if (!empty($entity->panelizer[$view_mode])) {
$entity->panelizer[$view_mode]->did = NULL;
if (isset($form['panelizer'][$view_mode]['name'])) {
$entity->panelizer[$view_mode]->entity_id = $form['panelizer'][$view_mode]['name']['#entity_id'];
$entity->panelizer[$view_mode]->revision_id = $form['panelizer'][$view_mode]['name']['#revision_id'];
}
}
}
}
}
}
}
}