diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module index 67dbb6f..992ae57 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module @@ -639,7 +639,7 @@ function fieldable_panels_panes_ctools_plugin_directory($owner, $plugin_type) { function fieldable_panels_panes_ctools_access_get($argument) { list($op, $fpid) = explode(':', $argument); $entity = fieldable_panels_panes_load($fpid); - if (!$entity || !fieldable_panels_panes_access('update', $entity)) { + if (empty($entity) || !fieldable_panels_panes_access('update', $entity)) { return; } @@ -661,7 +661,7 @@ function fieldable_panels_panes_ctools_access_get($argument) { function fieldable_panels_panes_ctools_access_set($argument, $access) { list($op, $fpid) = explode(':', $argument); $entity = fieldable_panels_panes_load($fpid); - if (!$entity || !fieldable_panels_panes_access('update', $entity)) { + if (empty($entity) || !fieldable_panels_panes_access('update', $entity)) { return; } @@ -675,7 +675,7 @@ function fieldable_panels_panes_ctools_access_set($argument, $access) { function fieldable_panels_panes_ctools_access_clear($argument) { list($op, $fpid) = explode(':', $argument); $entity = fieldable_panels_panes_load($fpid); - if (!$entity || !fieldable_panels_panes_access('update', $entity)) { + if (empty($entity) || !fieldable_panels_panes_access('update', $entity)) { return; } @@ -719,7 +719,8 @@ function template_preprocess_fieldable_panels_pane(&$vars) { */ function fieldable_panels_panes_preprocess_panels_pane(&$vars) { if ($vars['pane']->type == 'fieldable_panels_pane') { - if ($entity = fieldable_panels_panes_load_entity($vars['pane']->subtype)) { + $entity = fieldable_panels_panes_load_entity($vars['pane']->subtype); + if (!empty($entity)) { if ($entity->link && !empty($vars['title'])) { $vars['title'] = l($vars['title'], $entity->path); } @@ -745,9 +746,7 @@ function fieldable_panels_panes_load($fpid, $vid = NULL) { $conditions = (isset($vid) ? array('vid' => $vid) : array()); $entities = fieldable_panels_panes_load_multiple(array($fpid), $conditions); - if ($entities) { - return reset($entities); - } + return $entities ? reset($entities) : FALSE; } /** @@ -790,7 +789,7 @@ function fieldable_panels_panes_delete_revision($fpid, $vid) { if ($revision = fieldable_panels_panes_load($fpid, $vid)) { // Prevent deleting the current revision. $entity = fieldable_panels_panes_load($revision->fpid); - if ($vid == $entity->vid) { + if (empty($entity) || empty($entity->vid)) { return FALSE; } diff --git a/includes/PanelsPaneController.class.php b/includes/PanelsPaneController.class.php index f9d0ee1..7a19691 100644 --- a/includes/PanelsPaneController.class.php +++ b/includes/PanelsPaneController.class.php @@ -40,10 +40,12 @@ class PanelsPaneController extends DrupalDefaultEntityController { parent::attachLoad($queried_entities, $revision_id); // We need to go through and unserialize our serialized fields. - foreach ($queried_entities as $entity) { - foreach (array('view_access', 'edit_access') as $key) { - if (is_string($entity->$key)) { - $entity->$key = unserialize($entity->$key); + if (!empty($queried_entities)) { + foreach ($queried_entities as $entity) { + foreach (array('view_access', 'edit_access') as $key) { + if (is_string($entity->$key)) { + $entity->$key = unserialize($entity->$key); + } } } } @@ -268,27 +270,30 @@ class PanelsPaneController extends DrupalDefaultEntityController { if (!empty($fpids)) { $entities = fieldable_panels_panes_load_multiple($fpids, array()); - try { - foreach ($entities as $fpid => $entity) { - // Call the entity-specific callback (if any): - module_invoke_all('fieldable_panels_pane_delete', $entity); - module_invoke_all('entity_delete', $entity, 'fieldable_panels_pane'); - field_attach_delete('fieldable_panels_pane', $entity); - } + if (!empty($entities)) { + try { + foreach ($entities as $fpid => $entity) { + // Call the entity-specific callback (if any): + module_invoke_all('fieldable_panels_pane_delete', $entity); + module_invoke_all('entity_delete', $entity, 'fieldable_panels_pane'); + field_attach_delete('fieldable_panels_pane', $entity); + } - // Delete after calling hooks so that they can query entity tables as needed. - db_delete('fieldable_panels_panes') - ->condition('fpid', $fpids, 'IN') - ->execute(); + // Delete after calling hooks so that they can query entity tables as + // needed. + db_delete('fieldable_panels_panes') + ->condition('fpid', $fpids, 'IN') + ->execute(); - db_delete('fieldable_panels_panes_revision') - ->condition('fpid', $fpids, 'IN') - ->execute(); - } - catch (Exception $e) { - $transaction->rollback(); - watchdog_exception('fieldable_panels_pane', $e); - throw $e; + db_delete('fieldable_panels_panes_revision') + ->condition('fpid', $fpids, 'IN') + ->execute(); + } + catch (Exception $e) { + $transaction->rollback(); + watchdog_exception('fieldable_panels_pane', $e); + throw $e; + } } // Clear the page and block and entity_load_multiple caches. diff --git a/includes/fieldable_panels_pane.migrate.inc b/includes/fieldable_panels_pane.migrate.inc index f438193..a7c9682 100644 --- a/includes/fieldable_panels_pane.migrate.inc +++ b/includes/fieldable_panels_pane.migrate.inc @@ -189,14 +189,16 @@ class MigrateDestinationFieldablePanelsPanes extends MigrateDestinationEntity { if ($migration->getSystemOfRecord() == Migration::DESTINATION) { // Incoming data overrides existing data, so only copy non-existent // fields. - foreach ($old_fieldable_panels_panes as $field => $value) { - // An explicit NULL in the source data means to wipe to old value (i.e. - // don't copy it over from $old_fieldable_panels_panes). - if (property_exists($fieldable_panels_pane, $field) && $fieldable_panels_pane->$field === NULL) { - // Ignore this field. - } - elseif (!isset($fieldable_panels_pane->$field)) { - $fieldable_panels_pane->$field = $old_fieldable_panels_panes->$field; + if (!empty($old_fieldable_panels_panes)) { + foreach ($old_fieldable_panels_panes as $field => $value) { + // An explicit NULL in the source data means to wipe to old value + // (i.e. don't copy it over from $old_fieldable_panels_panes). + if (property_exists($fieldable_panels_pane, $field) && $fieldable_panels_pane->$field === NULL) { + // Ignore this field. + } + elseif (!isset($fieldable_panels_pane->$field)) { + $fieldable_panels_pane->$field = $old_fieldable_panels_panes->$field; + } } } } diff --git a/plugins/content_types/fieldable_panels_pane.inc b/plugins/content_types/fieldable_panels_pane.inc index bd7eac3..9802d0b 100644 --- a/plugins/content_types/fieldable_panels_pane.inc +++ b/plugins/content_types/fieldable_panels_pane.inc @@ -40,7 +40,7 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_content_type( } else { $entity = fieldable_panels_panes_load_entity($subtype_name); - if ($entity) { + if (!empty($entity)) { return _fieldable_panels_panes_custom_content_type($entity); } } @@ -53,11 +53,13 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_content_types $types = _fieldable_panels_panes_default_content_type(); $ids = db_query('SELECT fpid FROM {fieldable_panels_panes} WHERE reusable = 1')->fetchCol(); - if ($ids) { + if (!empty($ids)) { $entities = fieldable_panels_panes_load_multiple($ids); - foreach ($entities as $entity) { - $subtype = _fieldable_panels_panes_custom_content_type($entity); - $types[$subtype['name']] = $subtype; + if (!empty($entities)) { + foreach ($entities as $entity) { + $subtype = _fieldable_panels_panes_custom_content_type($entity); + $types[$subtype['name']] = $subtype; + } } } @@ -69,8 +71,8 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_content_types */ function fieldable_panels_panes_fieldable_panels_pane_content_type_render($subtype, $conf, $panel_args = array(), $context = array()) { $entity = fieldable_panels_panes_load_entity($subtype); - $view_mode = isset($conf['view_mode']) ? $conf['view_mode'] : 'full'; - if ($entity && !empty($entity->fpid) && fieldable_panels_panes_access('view', $entity)) { + if (!empty($entity) && !empty($entity->fpid) && fieldable_panels_panes_access('view', $entity)) { + $view_mode = isset($conf['view_mode']) ? $conf['view_mode'] : 'full'; $settings = field_bundle_settings('fieldable_panels_pane', $entity->bundle); // Add pane config to the entity object before hook_view(). $entity->conf = $conf; @@ -106,11 +108,11 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_render($subty function fieldable_panels_panes_fieldable_panels_pane_content_type_admin_title($subtype, $conf) { $entity = fieldable_panels_panes_load_entity($subtype); - $output = t('Deleted/removed entity pane'); - if (isset($entity) && is_object($entity)) { - $title = !empty($entity->admin_title) ? $entity->admin_title : (!empty($entity->title) ? $entity->title : t('No title')); - - $output = $title; + if (!empty($entity) && is_object($entity)) { + $output = !empty($entity->admin_title) ? $entity->admin_title : (!empty($entity->title) ? $entity->title : t('No title')); + } + else { + $output = t('Deleted/removed entity pane'); } return $output; @@ -128,16 +130,15 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_admin_info($s */ function fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form($form, &$form_state) { $conf = &$form_state['conf']; - $subtype_name = $form_state['subtype_name']; if (!isset($form_state['entity'])) { - $form_state['entity'] = fieldable_panels_panes_load_entity($subtype_name); + $form_state['entity'] = fieldable_panels_panes_load_entity($form_state['subtype_name']); } $entity = $form_state['entity']; - // It's possible that we have a reference to an entity that is no longer valid. - // If so, bail, because otherwise field API will whitescreen. - if (!$entity) { + // It's possible that we have a reference to an entity that is no longer + // valid. If so, bail, because otherwise field API will whitescreen. + if (empty($entity)) { $form['error'] = array( '#markup' => t('The pane entity referenced does not appear to be valid. It was probably deleted and you should remove this pane.'), ); diff --git a/plugins/export_ui/fieldable_panels_pane.class.php b/plugins/export_ui/fieldable_panels_pane.class.php index 3252eca..39ddad5 100644 --- a/plugins/export_ui/fieldable_panels_pane.class.php +++ b/plugins/export_ui/fieldable_panels_pane.class.php @@ -144,55 +144,57 @@ class fieldable_panels_pane extends ctools_export_ui { $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2)); $rows = array(); - foreach ($entity_info['bundles'] as $bundle => $info) { - // Filter out bundles that already exist as ctools exportable objects. - if (isset($items[$bundle])) { - continue; - } + if (!empty($entity_info['bundles'])) { + foreach ($entity_info['bundles'] as $bundle => $info) { + // Filter out bundles that already exist as ctools exportable objects. + if (isset($items[$bundle])) { + continue; + } - $row = array(); + $row = array(); - $label = check_plain($info['label']); - $label .= ' ' . t('(Machine name: @type)', array('@type' => $bundle)) . ''; + $label = check_plain($info['label']); + $label .= ' ' . t('(Machine name: @type)', array('@type' => $bundle)) . ''; - $row[] = $label; + $row[] = $label; - $operations = array(); + $operations = array(); - $operations['list'] = array( - 'title' => t('list'), - 'href' => 'admin/structure/fieldable-panels-panes/manage/' . $bundle, - ); + $operations['list'] = array( + 'title' => t('list'), + 'href' => 'admin/structure/fieldable-panels-panes/manage/' . $bundle, + ); - $operations['add'] = array( - 'title' => t('add'), - 'href' => 'admin/structure/fieldable-panels-panes/manage/' . $bundle . '/add', - ); + $operations['add'] = array( + 'title' => t('add'), + 'href' => 'admin/structure/fieldable-panels-panes/manage/' . $bundle . '/add', + ); - $operations['fields'] = array( - 'title' => t('manage fields'), - 'href' => $this->field_admin_path($bundle, 'fields'), - ); + $operations['fields'] = array( + 'title' => t('manage fields'), + 'href' => $this->field_admin_path($bundle, 'fields'), + ); - $operations['display'] = array( - 'title' => t('manage display'), - 'href' => $this->field_admin_path($bundle, 'display'), - ); + $operations['display'] = array( + 'title' => t('manage display'), + 'href' => $this->field_admin_path($bundle, 'display'), + ); - $ops = theme('links', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline')))); + $ops = theme('links', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline')))); - $row[] = $ops; - $rows[] = $row; - } + $row[] = $ops; + $rows[] = $row; + } - if (!empty($rows)) { - $variables = array( - 'caption' => t('Legacy bundles that are not managed by the bundle administrative UI are listed here.'), - 'header' => $header, - 'rows' => $rows, - ); + if (!empty($rows)) { + $variables = array( + 'caption' => t('Legacy bundles that are not managed by the bundle administrative UI are listed here.'), + 'header' => $header, + 'rows' => $rows, + ); - return theme('table', $variables); + return theme('table', $variables); + } } } diff --git a/plugins/views/fieldable_panels_panes_handler_field_is_current.inc b/plugins/views/fieldable_panels_panes_handler_field_is_current.inc index f8f16df..fe1f40d 100644 --- a/plugins/views/fieldable_panels_panes_handler_field_is_current.inc +++ b/plugins/views/fieldable_panels_panes_handler_field_is_current.inc @@ -25,7 +25,7 @@ class fieldable_panels_panes_handler_field_is_current extends views_handler_fiel if (!empty($value->{$this->aliases['fpid']}) && !empty($value->{$this->aliases['vid']})) { $this->entities[$row_index] = fieldable_panels_panes_load($value->{$this->aliases['fpid']}, $value->{$this->aliases['vid']}); - if ($this->entities[$row_index]->vid == $this->entities[$row_index]->current_vid) { + if (!empty($this->entities[$row_index]) && $this->entities[$row_index]->vid == $this->entities[$row_index]->current_vid) { $values[$row_index]->{$this->field_alias} = $this->options['current_text']; } else {