0

I get this Notice:

Notice: Undefined offset: 1 in custom_context_section_condition->_get_url_section() (line 110 of modules/custom/custom_context/plugins/custom_context_section_condition.inc).

  **
  * Get section by url
  */
  function _get_url_section() {
    // get the correct URL
    $path = $_GET['q'];
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $path = drupal_get_path_alias($_GET['q']);
    }
    $path = explode('/', $path);

    // Remove reserved part from path when defined as constant (see custom_context.module)
    if (in_array(arg(0), unserialize(URL_PATH_PART))) {
      array_shift($path);
    }
    // Remove reserved string from path when defined as constant (see custom_context.module)
    else if ($new_path = _custom_context_strpos_replace_arr($_GET['q'], unserialize(URL_PATH_STRING))) {
      $path = explode('/', $new_path);
    }

    // Get section by path
    $value = str_replace('-', ' ', $path[1]);
    $terms = taxonomy_get_term_by_name($value);

    // make sure we are getting the right section under the correct city
    // check if city context exist
    $city = NULL;
    $contexts = context_active_contexts();
    if ($contexts = context_active_contexts()) {
      foreach ($contexts as $key => $context) {
        if ($key == 'city') {
          $city = $context->conditions['custom_city']['city']['term'];
          break;
        }
      }
    }
    else {
      $city_context = new custom_context_city_condition(this, array());
      $cities = $city_context->_get_city($node);
      $city = array_shift($cities);
    }

    // check parent tid here
    foreach ($terms as $key => $term) {
      $parents = taxonomy_get_parents($term->tid);
      $parent = array_shift($parents);
      if ($city->tid != $parent->tid) {
        unset($terms[$key]);
      }
    }
    return $terms;
  }

This part:

if ($city->tid != $parent->tid) {
  unset($terms[$key]);
}

Also says: Notice: Trying to get property of non-object

Any idea whats wrong in my code?

2
  • The value of $path is Array ( [0] => node ), would that be a problem? Commented Jul 4, 2012 at 3:05
  • Please add line numbers or tell us where line 110 is in the first code block.
    – BetaRide
    Commented Jul 4, 2012 at 3:34

2 Answers 2

3

In the code above $parent is an array so $parent->tid is illegal. I am not sure what you are trying to find in the $parent but you should also note that the parent array has numeric indicies. So you probably have to do it this wat $parent[45] or $parent[$city->tid] depending on your requirement

0
2

For the second part, either $city or $parent isn't an object. They are NULL of an other type. Have a look with your debugger or dump the contens of the variables to see what they contain.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.