node.class.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @file
  4. * Define Linkit node search plugin class.
  5. */
  6. /**
  7. * Reprecents a Linkit node search plugin.
  8. */
  9. class LinkitSearchPluginNode extends LinkitSearchPluginEntity {
  10. /**
  11. * Overrides LinkitSearchPluginEntity::createRowClass().
  12. *
  13. * Adds an extra class if the node is unpublished.
  14. */
  15. function createRowClass($entity) {
  16. if ($this->conf['include_unpublished'] && $entity->status == NODE_NOT_PUBLISHED) {
  17. return 'unpublished-node';
  18. }
  19. }
  20. /**
  21. * Overrides LinkitSearchPluginEntity::getQueryInstance().
  22. */
  23. function getQueryInstance() {
  24. // Call the parent getQueryInstance method.
  25. parent::getQueryInstance();
  26. // If we don't want to include unpublished nodes, add a condition on status.
  27. if ($this->conf['include_unpublished'] == 0) {
  28. $this->query->propertyCondition('status', NODE_PUBLISHED);
  29. }
  30. }
  31. /**
  32. * Overrides LinkitSearchPlugin::buildSettingsForm().
  33. */
  34. function buildSettingsForm() {
  35. // Get the parent settings form.
  36. $form = parent::buildSettingsForm();
  37. $form[$this->plugin['name']]['include_unpublished'] = array(
  38. '#title' => t('Include unpublished nodes'),
  39. '#type' => 'checkbox',
  40. '#default_value' => isset($this->conf['include_unpublished']) ? $this->conf['include_unpublished'] : 0,
  41. '#description' => t('In order to see unpublished nodes, the user must also have permissions to do so. '),
  42. );
  43. return $form;
  44. }
  45. }