1

I want add export link in some place if current path plus '/export' exists. But can't understand how check such urls. The problem is when path exists with less number of arguments drupal_valid_path() returns TRUE. For example I have path 'reports' but don't have path 'reports/export'. I check paths like this:

$export_path = current_path() . '/export';
if (drupal_valid_path($export_path)) {
    $export_options = drupal_get_query_parameters();
    $link_options = array(
       'attributes' => array(
            'class' => array('open'),
            'target' => '_blank',
        ),
        'query' => $export_options,
    );
    $vars['print_links'] = l('', $export_path, $link_options);
}

How do I need check paths?

2 Answers 2

2

Solve this problem by addng code above.

$exposed_args_count = count(explode('/', $export_path));
$menu_item = menu_get_item($export_path);
if (($menu_item['number_parts'] == $exposed_args_count) && drupal_valid_path($export_path)) {
0

You can check it simply using arg() function. e.g you have path as www.example.com/testpage/export

$export_path = arg(0)."/".arg(1);
//$export_path will print its as 'testpage/export'

So you can use the if condition as

if ($export_path=='testpage/export')) {

//Your data export code

}
2
  • There could be many arguments in urls and many urls to check. So it's not correct to check like you wrote.
    – FriOne
    Commented Sep 28, 2014 at 6:49
  • Thats fine. But i think there can be params in the urls that you know already.
    – user33576
    Commented Sep 28, 2014 at 6:52

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.