Jump to content
design-a-point

Custom namespace in modules

Recommended Posts

Hi there,

I just tried to implement a process module for a PW3 (3.0.32 devns) installation with a custom namespace and found that there's an issue with assigning the new Process to the newly created admin page.

( ! ) Warning: class_parents(): Class ProcessWire\ProcessNamespaceTest does not exist and could not be loaded in /var/www/public/pw3/wire/core/Functions.php on line 721

It looks like the custom namespace is ignored...

The demo module looks like this:

<?php namespace ACME;

use ProcessWire\Process;

/**
 * ProcessNamespaceTest/ProcessNamespaceTest.module
 */
class ProcessNamespaceTest extends Process
{
  ...

I also added the appropriate settings for autoloading in the composer.json file and did a composer dump-autoload:

"autoload": {
  "files": [
    "wire/core/ProcessWire.php"
  ],
  "psr-4": {
    "ACME\\": [
      "site/modules/ProcessNamespaceTest"
    ]
  }
}

 

Does anyone have an idea if I missed something?

 

Thanks

Alex

Share this post


Link to post
Share on other sites

I think you might have missed a leading '\' on the 'Processwire' name. Try this...

use \ProcessWire\Process;

Not 100%  sure though.

Share this post


Link to post
Share on other sites
21 minutes ago, netcarver said:

I think you might have missed a leading '\' on the 'Processwire' name. Try this...


use \ProcessWire\Process;

Not 100%  sure though.

Thanks for that hint, but the warning still persists...

It's also worth to mention that everything works fine if the namespace is initially set to ProcessWire. If the namespace is changed back to ACME later, the module still works without problems. It's only the page editor for the admin page where the warning occurs.

Share this post


Link to post
Share on other sites

Jumplinks 2 (in development) makes use of namespaces. I simply require a bootstrap file (say, bootstrap.php) at the top of the module's main file, and this file uses the PW classloader to add the namespace, like so:

$this->classLoader->addNamespace('Jumplinks', __DIR__ . '/src/Jumplinks');

As such, you do not need to use the composer.json file for this.

Share this post


Link to post
Share on other sites

Hi Mike,

thanks for your answer! I once tried to use PW's build in class loader but wasn't sure where to call addNamespace...

What do you mean by 

On 29.8.2016 at 6:08 PM, Mike Rockett said:

at the top of the module's main file

If the main module file resides directly in the module's folder, it should be like this?

<?php namespace ACME;

$this->classLoader->addNamespace('ACME', __DIR__);

use ProcessWire\Process;

/**
 * ProcessNamespaceTest/ProcessNamespaceTest.module
 */
class ProcessNamespaceTest extends Process
{
  ...

This is not working... I'm also not sure what $this refers to in this context ???

Share this post


Link to post
Share on other sites

I think that PW modules should remain in whatever namespace PW is using. In the case of 2.8, that is the root namespace. In the case of 3.0, that is \ProcessWire. Then, include a directory namespace (such as src), and use your namespaces there only. This seems most logical to me...

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By VeiJari
      Hello forum,
      This is really a weird one, because front end editing works in a earlier website we did to a customer. 
      When I check the source code for current website it does initiate front end edit: 
      <span id=pw-edit-1 class='pw-edit pw-edit-InputfieldPageTitle' data-name=title data-page=1021 data-lang='1017' style='position:relative'><span class=pw-edit-orig>Tekijät</span><span class=pw-edit-copy id=pw-editor-title-1021 style='display:none;-webkit-user-select:text;user- select:text;' contenteditable>Tekijät</span></span>  But when I double click nothing happens (yes I'm 100% sure I'm superuser and logged in)
      I also tried to apply the front end with other methods than:
      $page->edit('title'); But didn't work either.
      We are using jquery 2.2.4, so it should not be a problem.
      Is this a bug related to current master or something else?
      Someone else having this problem as well?
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      Despite my searches of the forum I'm somewhat confused about how to create new child pages on the frontend when a user clicks on a button on the parent page. I also have an equivalent button that is intended for uploading a .csv file to automatically create multiple new pages. This basically relates to a club (parent) and members (child) template configuration. Hopefully this explanation makes sense.
      A button should be able to launch the code needed to initiate the script required to create a new page using something like:
      <a href="/path/page.php">New +</a> <a href="/path/page.php">New ++</a> Does the code to create the new page or new pages need to be run from the template file for the child or the parent?
      A new individual member page will need to be editable manually at the point of page creation as well as subsequently, whereas multiple new pages will need to be editable after they have created and populated with data, again, as well as subsequently.
      I would very grateful for any advice or pointers as to how to achieve this.
       
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I was wondering if there is a way to restrict user navigation to specific pages.
      Login (home.php - not to be displayed)
          |__  About (not to be displayed)
          |__  Clubs (not to be displayed)
          |            |__ Club (to be displayed)
          |                       |__  Club Members (to be displayed)
          |__ League (not to be displayed)
          |            |__Season (not to be displayed)
          |                       |__  Match (not to be displayed)
          |__  News (blog.php -  to be displayed)
          |
      etc, etc
      Based on the above the navigation needs to appear simply as:
      ---------------------------------------------------------------------------
                           Club    Club Members    News    
      ---------------------------------------------------------------------------
      Any thoughts appreciated.
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I am trying to create a process whereby when a user logs in to their profile page (the user is automatically redirected to their profile page on login) and they then go to their 'members' page and creates a child page ('club-member'), the data stored in the user template ($user->usercode) is automatically added to the equivalent field on the club-member page.  This will be applicable only to the template used for the 'club-member' pages. Once the new page has been created the equivalent 'usercode' field on the 'club-member' page should not be subsequently editable.
      Below is the page hierarchy for visual reference:
      Login (home)
          |__  profile
                      |__  members
                                     |__  club-members
      It seems like an AddHookBefore might be the solution here such as:
      wire()->addHookBefore("Pages::saveReady", function($event) { $page = $event->arguments(0); if($page->template == 'club-member') { $clubcode = $user->club_code; $field = $page->club_code; $field->set('value', $clubcode); } }); I am I on the right track or is there a better way to achieve this?
      Any thoughts appreciated.
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I've setup a page where a member can edit contact details via the frontend displaying the field content using the <edit> ... </edit> tags.
      This works fine when the fields actually contain data. However fields that contain no data (i.e. empty) do not appear to be editable. No edit cursor appears (- possibly owing to the field width being 0px?)
      Is the only solution to recreate the page using a form, for example,  or is there a simple way to allow blank fields to be editable on the frontend?
      I wondered if anyone else has found a solution to this problem. Any assistance would be appreciated.
×
×
  • Create New...