function ctools_context_next_id

Get the next id available given a list of already existing objects.

This finds the next id available for the named object.

Parameters

array $objects: A list of context descriptor objects, i.e, arguments, relationships, contexts, etc.

string $name: The name being used.

Return value

int The next integer id available.

4 calls to ctools_context_next_id()
CtoolsContextIDTestCase::testNextContextId in tests/context.test
Test ctools_context_next_id in various scenarios.
ctools_context_ajax_item_add in includes/context-admin.inc
Ajax entry point to add an context
ctools_context_get_defaults in includes/context-admin.inc
Get the defaults for a new instance of a context plugin.
page_manager_page_argument_form_change_submit in page_manager/plugins/tasks/page.admin.inc
Submit handler to change an argument.

File

includes/context.inc, line 1122

Code

function ctools_context_next_id($objects, $name) {
    $id = 0;
    // Figure out which instance of this argument we're creating.
    if (!$objects) {
        return $id + 1;
    }
    foreach ($objects as $object) {
        if (isset($object['name']) && $object['name'] === $name) {
            if (isset($object['id']) && $object['id'] > $id) {
                $id = (int) $object['id'];
            }
            // @todo If obj has no 'id', should we increment local id? $id = $id + 1;
        }
    }
    return $id + 1;
}