/** * {@inheritdoc} */ public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { ctools_include('plugins'); $definition = ctools_get_plugins($this->pluginOwner, $this->pluginType, $plugin_id); if (!$definition && $exception_on_invalid) { throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist.', $plugin_id)); } return $definition; }
/** * Include some ctools stuff required for drupal ajax to work properly. * @see ctools_export_ui::edit_form() */ public function edit_form(&$form, &$form_state) { // This is needed in order to get the ajax working in the ctools form. ctools_include('plugins'); ctools_include('export'); ctools_get_plugins('ctools', 'export_ui', 'entity_collection'); parent::edit_form($form, $form_state); // We need to define our own function, the one provided by ctools does not // work with the Drupal ajax API. $form['info']['name']['#machine_name']['exists'] = 'entity_collection_bundle_exists'; }
/** * Load information about Plugins by module and type * * This is a wrapper around ctools_get_plugins, with the benefit of loading the * relevant ctools include. We store the information locally in case its * required for reuse in this operation. * * @param string $module * The module providing the plugin * @param string $type * The type of plugin */ public function getPlugins($module, $type) { ctools_include('plugins'); $plugins = ctools_get_plugins($module, $type); if (!empty($plugins)) { if (!isset($this->plugins[$module])) { $this->plugins[$module] = array(); } $this->plugins[$module][$type] = $plugins; } }
/** * @param $event_type * * @return array */ public function formatJson($event_type) { ctools_include('plugins'); $formatters = ctools_get_plugins('bat_event', 'bat_eventstyle'); foreach ($formatters as $formatter) { $class = ctools_plugin_get_class($formatter, 'handler'); $object_formatter = new $class($this->event); $event = $object_formatter->format($event_type); } return $event; }
function edit_form_validate(&$form, &$form_state) { ctools_get_plugins('openlayers', 'layer_types'); $layer = openlayers_layer_type_load($form_state['values']['layer_type']); $form_state['values']['data'] = $form_state['values'][$form_state['values']['layer_type']]; if (empty($form_state['values']['layer_type'])) { form_set_error('layer_type', 'Layer type cannot be empty.'); } $parent = get_parent_class($layer); $parent_object = new $parent(); $form_state['values']['data'] += $layer->options_init(); $form_state['values']['data'] += $parent_object->options_init(); $layer_types = openlayers_layer_types(); foreach ($layer_types as $layer_type) { unset($form_state['values'][$layer_type['name']]); } unset($form_state['values']['layer_type']); if (method_exists($layer, 'options_form_validate')) { $layer->options_form_validate($form, $form_state['values']); } parent::edit_form_validate($form, $form_state); }
/** * {@inheritdoc} * * @todo: We should generalize this, as it's repeated often. */ public function view($id) { $cache_id = array( 'md' => $this->getModule(), 'tp' => $this->getType(), 'id' => $id, ); $cached_data = $this->getRenderedCache($cache_id); if (!empty($cached_data->data)) { return $cached_data->data; } if (!$plugin = ctools_get_plugins($this->getModule(), $this->getType(), $id)) { // Since the discovery resource sits under 'api/' it will pick up all // invalid paths like 'api/invalid'. If it is not a valid plugin then // return a 404. throw new \RestfulNotFoundException('Invalid URL path.'); } // Loop over all the defined public fields. foreach ($this->getPublicFields() as $public_field_name => $info) { $value = NULL; if ($info['create_or_update_passthrough']) { // The public field is a dummy one, meant only for passing data upon // create or update. continue; } // If there is a callback defined execute it instead of a direct mapping. if ($info['callback']) { $value = static::executeCallback($info['callback'], array($plugin)); } // Map row names to public properties. elseif ($info['property']) { $value = $plugin[$info['property']]; } // Execute the process callbacks. if ($value && $info['process_callbacks']) { foreach ($info['process_callbacks'] as $process_callback) { $value = static::executeCallback($process_callback, array($value)); } } $output[$public_field_name] = $value; } $this->setRenderedCache($output, $cache_id); return $output; }
/** * Overrides ctools_export_ui::list_build_row(). */ public function list_build_row($queue, &$form_state, $operations) { global $user; // Rename the 'Edit' operation, as that will be re-assigned to edit subqueue // items. $operations['edit']['title'] = t('Configure'); // Remove the 'subqueues' operation from queue that have a single // subqueue, and remove the 'edit subqueue' operation for the rest. $handlers = ctools_get_plugins('entityqueue', 'handler'); if ($handlers[$queue->handler]['queue type'] == 'single') { unset($operations['subqueues']); unset($operations['delete subqueue']); $operations['edit subqueue']['href'] = str_replace('%entityqueue_subqueue', $queue->subqueue_id, $operations['edit subqueue']['href']); } else { unset($operations['edit subqueue']); } // Set up sorting. switch ($form_state['values']['order']) { case 'disabled': $this->sorts[$queue->name] = empty($queue->disabled) . $queue->name; break; case 'title': $this->sorts[$queue->name] = $queue->label; break; case 'name': $this->sorts[$queue->name] = $queue->name; break; case 'storage': $this->sorts[$queue->name] = $queue->type . $queue->name; break; } $item = array('#theme' => 'entityqueue_overview_item', '#label' => $queue->label, '#name' => $queue->name, '#status' => $queue->export_type); $target_type = entityqueue_get_handler($queue)->getTargetTypeLabel(); $handler_label = entityqueue_get_handler($queue)->getHandlerLabel(); if ($handlers[$queue->handler]['queue type'] == 'single') { $subitems = format_plural($queue->subitems, '1 item', '@count items'); } else { $subitems = format_plural($queue->subitems, '1 subqueue', '@count subqueues'); } // Remove operations the user doesn't have access to. if (!user_access('administer entityqueue', $user)) { unset($operations['edit'], $operations['export'], $operations['clone']); unset($operations['disable'], $operations['delete']); } if (!entityqueue_queue_access('update', $queue)) { unset($operations['edit subqueue'], $operations['edit']); } $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline')))); $this->rows[$queue->name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations')); $this->rows[$queue->name] = array('data' => array(array('data' => $item, 'class' => array('entityqueue-ui-queue')), array('data' => filter_xss_admin($target_type), 'class' => array('entityqueue-ui-target-type')), array('data' => filter_xss_admin($handler_label), 'class' => array('entityqueue-ui-handler')), array('data' => $subitems, 'class' => array('entityqueue-ui-items')), array('data' => $ops, 'class' => array('entityqueue-ui-operations', 'ctools-export-ui-operations'))), 'title' => t('Machine name: @name', array('@name' => $queue->name)), 'class' => array(!empty($queue->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled')); }
/** * Get a list of ctools plugins based on plugin slot and type passed. */ public function getPlugins($plugin_slot, $plugin_type) { ctools_include('plugins'); // It can be an array, some plugin slots accept multiple values. $plugin_names = $this->getPluginName($plugin_slot); if ($plugin_names == NULL) { return array(); } if (!is_array($plugin_names)) { $plugin_names = array($plugin_names); } // If $plugin_name is empty ctools_get_plugins() returns an array of // plugins. if (empty($plugin_names) && !$multiple) { return ctools_get_plugins('versioncontrol', $plugin_type); } $plugins = array(); foreach ($plugin_names as $plugin_name) { $plugin = ctools_get_plugins('versioncontrol', $plugin_type, $plugin_name); if (!is_array($plugin) || empty($plugin)) { throw new Exception("Attempted to get a plugin of type '{$plugin_type}' named '{$plugin_name}', but no such plugin could be found.", E_WARNING); } $plugins[] = $plugin; } return $plugins; }