Creating an API

Hi Alex,

I wanted to know the process of creating a new API.
I understand the flow as below so far :

  1. Create a new module (? can I also create it without module ?) : mod with function func
  2. make the controller : lib/controller/con.php
  3. create result view as view.twig (within views)
  4. add the route to routes-web.php
    like this : $app->get(’/mod’, ‘\Xibo\Controller\con:func’)->name(‘view’);

Of course I am missing out a lot of things.
Can you help me correct the method / workflow?

Thanks,
Reema

Could you specify what exactly do you want to achieve please?

In general custom modules/themes that you can create should go to /custom folder with config file (to avoid issues with upgrading)

You should be able to find required information in the manual pages here - https://xibo.org.uk/manual/en/advanced.html

It looks to me like you’re interested in extending page from the manual, however as I don’t know what exactly you want to add I might be wrong there.

I wanted to add a new page in advanced section on the left side (after log).
Where I want to populate an overview of how many users used which display and which content/layout was watched most.

Hi,

Are there any updates from your end?
There are no manuals to create API in player end in advanced section.
At least the windows source code is expected to be customizable.

Thanks,
Reema

I’m not sure what you mean by how many users used which display as for content on the displays then that’s already reported in the proof of play statistics (which can be called via API as well as web ui).
Or do you need some other specific data that is not included there?

You certainly could create a new menu item with twig views and controller that would have the function you want then connect that to middleware for webui/api access route - that is explained in extending manual page

Okay. I will give you an example of the workflow I want to understand.

  1. adding a page on left side panel in design section “tags”
  2. which will fetch all tags from the “TAG” table and display in the page

I will need to add the twig file also. but there is not documentation for the whole flow which to connect when. would be great help if you could assist.

So far I have done below : (creating a new tag page)

  1. added a route : $app->get(‘/tag/view’, ‘\Xibo\Controller\Tag:displayPage’)->name(‘tag.view’);
  2. added a new controller tag.php
  3. added a view tag-page.twig
  4. modified authed-sidebar.twig to contain tags tab

clicking it is currently giving 500 error.

You could open Log page in another tab and see what exactly is causing the problem, at a guess not everything is connected as it should be.

It would be best to have all that custom code in the /custom folder otherwise there might be issues during CMS upgrade.

As such I’d highly recommend creating a custom theme https://xibo.org.uk/manual/en/advanced_theme.html

and then have a look here, this example should be helpful
https://xibo.org.uk/manual/en/advanced_extending.html#examples

Hi Peter,

I followed your references. And created config.php inside web/theme/custom/client/config.php as below :
$config = array(
‘theme_name’ => ‘ClientTheme’,
‘theme_title’ => ‘Client CMS’,
‘app_name’ => ‘Client CMS’,
‘theme_url’ => ‘http://client.com/’,
‘cms_source_url’ => ‘http://client.com/’,
‘cms_install_url’ => ‘http://client.com/’,
‘cms_release_notes_url’ => ‘http://client.com/’,
‘view_path’ => PROJECT_ROOT . ‘/web/theme/custom/client/views’
);

as mentioned here :

Loading this said unexpected error.
Its obviously because config array is not supposed to contain the last parameter. Which config.php should be edited. It seems I am editing the wrong config, wrongly.

That seems correct actually, assuming that web/theme/custom/client/views exists and that you have your custom .twig files in it.

I believe you’re editing correct file ie you’ve created the config.php in your custom theme folder ie web/theme/custom/client/

the $config array can and in this case should have the view_path parameter as you will need to override some twig files.

If you remove the view_path then it loads the theme fine, but with it, you get the error after theme change/reload?

Could you perhaps open dev tools and see what the error is exactly please?

Overriding would mean that I only need to keep the updated twig file here, and remaining it takes up from the original project root (…/…/views) (correct? or do I need to copy all the other twigs also even though they aren’t changed)
So, I have copied the authed-sidebar.twig and added the tag param here :

Ideally, it should work normally (like load the side bar ) and load other things normally. Just with Tag added. But that is not happening.

There are no errors in the dev tool.

Here is my config.php

Earlier (without the “custom” method), when I was changing things directly, I had to add below (other than change in authed-sidebar.twig)

  1. :\xampp\htdocs\xibo\lib\Controller\Tag.php:
  2. C:\xampp\htdocs\xibo\lib\routes-web.php:
    //$app->get(‘/tag/view’, ‘\Xibo\Controller\Tag:displayPage’)->name(‘tag.view’);
  3. C:\xampp\htdocs\xibo\views\tag-page.twig

Will the custom module already do these for me?
If not, maybe thats why its not connecting them and doesnt have a route.

The change you made in Custom or to be more specific in the authed-sidebar would be enough if you would provide a link to some external webpage or something like that.

However, since you are linking that to a new twig view file, then that file would need to exist in the /custom/views
and you’d need to have your controller and middleware in /custom as well

Then have the middleware “installed” in settings.php ie https://xibo.org.uk/manual/en/advanced_extending.html#examples

Hi Peter,

With this in the config.php :
$config = array(
‘theme_name’ => ‘client Theme’,
‘theme_title’ => ‘client solution’,
‘app_name’ => ‘client solution’,
‘theme_url’ => ‘http://client.com/’,
‘cms_source_url’ => ‘http://client.com/’,
‘cms_install_url’ => ‘http://client.com/’,
‘cms_release_notes_url’ => ‘http:/client.com/’
‘view_path’ => PROJECT_ROOT . ‘/web/theme/custom/client/views/’
);
It throws a 500 error and doesn’t even load the page. I dont think this is the way project root is to be set for a custom theme. When I only have a URL in the side bar, then also it doesnt load.

        {% if currentUser.routeViewable("/tag") %}
            <li class="sidebar-list"><a href="http://client.com/estore/">{% trans "Tags" %}</a></li>
        {% endif %}

Is this enough file structure when I only want to show a link in side bar that redirects to external page?

image

I made a little archive for you with very brief example of the modifications you’ve mentioned and controller / middleware connections.

Please see Private Message for more details.