Jump to content

Creating a module


Hari KT
 Share

Recommended Posts

Hi Guys,

Probably this has been asked, or have some modules which have the similar functionality. If you think so please link to it . I did searched a lot whether any question is asked. My apologies if I didn't find that.

I was wondering whether there is a way in PW which can create the needed fields for my template, and copy the template to the site/templates folder.

I noticed the __install() hook can be used to create Fields and FieldType.

$field = new Field();
$field->setName('somefunnyfield');
$data = array(
    'label' => 'Some nice label',
    'type' => 'Page',
);

Now the problems are more customization. Is there a module or something that can generate the necessary information from the already created fields?

The idea is want to create module say ( Blog ) which has certain fields and that can be installed in any PW installation, which out any changes other than in code.

Thank you

  • Like 1
Link to comment
Share on other sites

Hi Hari,

Creating fields using the API is very easy in PW. Have a look at various modules.

See also this thread:http://processwire.com/talk/topic/1051-adding-and-assigning-fields-without-using-gui/. Of course, you will have to adapt the code for a module (essentially a PHP class)....

The ___install() method is only called when the module is installed. Use this if you want to create something only one time, e.g. custom tables in your database that your module will be using. For "creating" other fields that will be used when the module runs in the admin (e.g. for process modules) you can throw those other methods in your module class, e.g. ___execute().  - [this one is executed when module is called]. Again, have a look at the various modules out there...

If you will be creating a module, what is the need for a template and a template file?

This bit I don't get :-)


Now the problems are more customization. Is there a module or something that can generate the necessary information from the already created fields?

Hmm...I like this idea about a blog module...

Edited multiple times for clarity and sanity!

Edited by kongondo
Link to comment
Share on other sites

Check out this module:

http://processwire.com/talk/topic/4420-page-list-migrator/

It is still in development, but it allows you to export a hierarchy of pages, templates and fields from one PW installation to another and import them into another PW installation. It currently doesn't copy the actually template.php files, but that is the easy part really :)

A blog setup is definitely one of the uses I am thinking of for this module, but at the moment you will find on the import page of the module the ability to import/create the pages/templates/fields for lists of countries and a few state lists.

I really do want to get back to finalizing this module, but it is in a usable state already although I would definitely recommend running it on a test installation of PW and not one with data that you care about first. If it works for your needs then use it wherever.

  • Like 2
Link to comment
Share on other sites

Hey kongondo - no worries. Maybe it will be ready for the modules directory sometime soon. I just need to find the time to get back to it - maybe this post will get me motivated to find the time - I do think it has lots of potential and most of the hard work is already done :)

  • 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...