Jump to content

Installing (sub)module ends up with memory allocation


Recommended Posts

So I've been working on this module https://github.com/maxa11an/processwire-body-builder but then I decided to split it up into multiple files for better overlooking of the module it self. 

But when I try to install either MarkupBodyBuilder or ProcessBodyBuilder I end up with Allowed memory size of 2147483648 bytes exhausted (tried to allocate 262144 bytes) in .../wire/core/Modules.php on line 2480

Afaik I don't need a className-method, but then I studied through all docs regarding module-dev and also went through a lot of integrated modules, but no luck there. So I was hoping on some advise of what I've missed or things to think about? 

 

Link to comment
Share on other sites

@Max Allan Niklasson,

Welcome to the forums.

I just had a quick look but you are basically caught in an infinite loop with all those includes.

You have this:

In MarkupBodyBuilder.module

<?php

    public function init()
    {
        include_once __DIR__ . "/vendor/autoload.php";
        include_once __DIR__ . "/BodyBuilder.module";// <==== THIS
        
        $this->addHookAfter("Fields::save", $this, 'hookWhenFieldSaved');
        $this->addHookAfter("Field::getInputfield", $this, 'hookHideTitle');
        $this->addHookAfter('Page::renderField', $this, 'hookRenderField');

        $this->twig = new Environment(new ArrayLoader(), [
            'autoescape' => false,
            'debug' => $this->config->debug
        ]);
        $this->twig->addExtension(new DebugExtension());
        return parent::init();
    }

In ProcessBodyBuilder.module

 

<?php

  public function init()
    {
        include_once __DIR__ . "/BodyBuilder.module";// <==== THIS

        $process = $this->wire('process');
        if ("$process" === "$this") {
            $this->headline($this->moduleInfo['page']['title']);
        }
        return parent::init();
    }

In BodyBuilder.module

<?php


namespace ProcessWire;

use Exception;

include_once "MarkupBodyBuilder.module";// <== THIS
include_once "ProcessBodyBuilder.module";// <== THIS

That is not how you reference other installed modules in ProcessWire;

Call them like this where you need them:

<?php

// inside a class
$bodyBuilder = $this->wire('modules')->get('BodyBuilder');
// outside a class
// $bodyBuilder = $modules->get('BodyBuilder');
// outside a class but inside a function
// $bodyBuilder = wire('modules')->get('BodyBuilder');

More info

https://processwire.com/api/ref/module/

Edited by kongondo
  • Like 1
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...