Expressing hooks

I have a safecracker form that submits a record. The form consists of a title, url_title and description. I want to create an extension hook that filters out certain words if they exist in the title entry.

I already have a function that takes care of cleaning function clean(){....} . I understand that we need to use an extension so that we can clear the header while saving the record.

Which extension box should use for this. can you give me a complete example of an extension cord. I am very good at PHP, but still new to hooks and how they should be implemented. I already read the EE documentation, but still found some confusion about using the hook

+4
source share
1 answer

First go to http://pkg.io/ and get the database extension file.

You probably want to use the "safecracker_submit_entry_start" hook to throw an error if an unclean word is entered. The most important part of the extension is registering the method and binding that you want to use, otherwise none of these codes will be launched.

Your code should look something like this:

 public function activate_extension() { // Setup custom settings in this array. $this->settings = array(); $data = array( 'class' => __CLASS__, 'method' => 'clean', // point to the method that should run 'hook' => 'safecracker_submit_entry_end', // point to the hook you want to use to trigger the above method. 'settings' => serialize($this->settings), 'version' => $this->version, 'enabled' => 'y' ); $this->EE->db->insert('extensions', $data); } 

Once the method has been called, you can start the cleanup. Make sure you pass the safecracker object to your clean method when defining it. For instance:

 public function clean($sc){ print_r($sc); } 
+5
source

Source: https://habr.com/ru/post/1402335/


All Articles