how to create a custom drupal 7 edit page - php

Im a TOTAL newbie to drupal development so please help me here, ok i have created a custom module which so far creates a custom database how do i go about creating a list page in the backend that i can use to manage each item in the DB and how do i go about creating a custom edit form to manage the insert/ edit / delete of each item
function rollover_res_schema() {
$rollover_res = array();
$rollover_res['rollover_res'] = array(
// Example (partial) specification for table "node".
'description' => 'Positioning for rollovers',
'fields' => array(
'rollover_res_id' => array(
'description' => 'The primary identifier for a node.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rollover_res_actual' => array(
'description' => 'The main rollover plain text.',
'type' => 'text',
'length' => 255,
'not null' => TRUE,
),
),
'indexes' => array(
'rollover_res_id' => array('rollover_res_id'),
),
'primary key' => array('rollover_res_id'),
);
return $rollover_res;
}

If you're a total newbie to Drupal development you should not be writing ANY code for the first month or two and you shouldn't do custom database code the first 6 months.
Start with learning about Fields and Views and once you grasp these you can add one of Display Suite, Context or Panels.

The key to learning how to do things in drupal is:
1) google search how
2) see how other modules do it. In this case, look at some core modules, such as the block module. In there you'll see the schema in .install, and you'll see some functions that create forms for saving new blocks, such as block_add_block_form. You'll need to read up on the form API. But basically, you'll create a form hook to display a form, a menu hook to create a page to hold the form, and a hook to submit the form. If you grep through your code base, you'll see many of examples that you can copy. In fact, there are drupal example modules you can download that cover most of the basics: https://www.drupal.org/project/examples
But to learn how to interact with the database, you could find a module that does something similar to what you're doing and look at how it uses hook_menu to set up page callbacks, forms for editing data.

Related

Programmatically adding a WC Booking in the cart fails

I am facing a problem to add such a product to the cart.
I manage to create the booking with:
$new_booking = get_wc_booking ($new_booking_data);
$new_booking -> create ($status);
But then I tried to apply these different methods without success:
add_cart_item_data ($cart_item_meta, $product_id); // error 500
or
$ new_booking_object -> add_cart_item ($cart_item_meta); // error 500
The $cart_item_meta object I create is like the following (some keys are duplicative, like for example start and start_date, because I observed in the code that both names are used, and I wanted to be sure to send at least the correct one ;-) ). BTW, by comparing with standard bookings created via the plugin form, I can be sure that the values I set in the array have the correct format.
$cart_item_meta = array(
'all_day' => false,
'cost' => $price,
'customer_id' => 1,
'user_id' => 1,
'date_created' => '',
'date_modified' => '',
'end' => $endDate,
'end_date' => $endDate,
'google_calendar_event_id' => 0,
'order_id' => $order->get_id(),
'order_item_id' => 0,
'parent_id' => 0,
'person_counts' => array($addPaxId => $pax),
'persons' => array($addPaxId => $pax),
'product_id' => $prodId,
'resource_id' => $resourceId,
'start' => $startDate,
'start_date' => $startDate,
'status' => 'in-cart',
'local_timezone' => 'Europe/Brussels',
);
I do get a record in the "posts" table, with the same specifics as a normal booking created by the normal way. In particular, I get post_type = wc_booking, and post_status = in-cart. But the cart remains empty.
I have compared all the entries in the database, and I can't see what is missing. But I'm definitely missing some of the understanding of the mechanics of WooCommerce ...
Does someone can help me to find a way to pass the final step: putting the created booking in the cart ? Thanks!
Well, maybe someone will be interested to know how I worked around, as so far I couldn't find a complete programming solution.
The products I want to book programmatically and add to the cart are existing products in my WooCommerce store. My purpose is just to use my own form to allow the customer to better understand what he books (I'm managing a flight simulators center with several machines), and the native WC Bookings form is not clear enough for me, and moreover it is really heavy and slow.
So after gathering customers info with my own form (simulator, duration, participants, timeslot), my problem was to put all this in the cart. I could achieve to create the relevant booking in the database, but not add it to the cart.
I observed that when you book via the standard form, you send a POST to the server on the same product page, including the following parameters (random data for example):
wc_bookings_field_persons_xxxx => 2 // 'xxxx' is the ID of the related 'bookable_person' in 'posts'
wc_bookings_field_start_date_month => 11 // November (sample)
wc_bookings_field_start_date_day => 26 // the 26th (sample)
wc_bookings_field_start_date_year => 2021 // Year (sample)
wc_bookings_field_start_date_time => 2021-11-26T15:00:00+0100
wc_bookings_field_start_date_local_timezone => Europe/Brussels
add-to-cart => 1147 // the product ID in 'posts'
So the simplest solution is to create a POST call (via form + button or button + ajax), setting the action/ajax url to the related product after filling the fields here above with the custom form...
EDIT: while I was thinking this was the solution, I discovered that it worked only when another tab in my browser previously 'opened the door' by adding the same product in the standard way. But when this tab is closed (or timeout), the above method fails and just open the product page. The 302 redirect that was operating stops to work for un unknown reason, and we get the standard 200 straight forward. No Cart.
So the question is still pending.

What are the possible ways to translate in MediaWiki from "backend", without an extension?

I have a MediaWiki 1.33.0 website with only one extension → ContactPage, with which I can have a simple contact form.
Using HTMLForms template engine (in which the default form-template for ContactPage is written), I have expanded the default form to include a selection menu.
My problem
Selection list array keys and values of this selection menu are written in English inside LocalSettings.php but my site isn't primarily in the LTR English, rather, it is in the RTL Hebrew and I would like them to appear in my site's native language for end users.
My own code pattern
wfLoadExtension( 'ContactPage' );
$wgContactConfig['default'] = array(
'RecipientUser' => 'Admin', // Must be the name of a valid account which also has a verified e-mail-address added to it.
'SenderName' => 'Contact Form on ' . $wgSitename, // "Contact Form on" needs to be translated
'SenderEmail' => null, // Defaults to $wgPasswordSender, may be changed as required
'RequireDetails' => true, // Either "true" or "false" as required
'IncludeIP' => false, // Either "true" or "false" as required
'MustBeLoggedIn' => false, // Check if the user is logged in before rendering the form
'AdditionalFields' => array(
'omgaselectbox' => [
'class' => 'HTMLSelectField',
'label' => 'Select an option',
'options' => [
'X' => 'X',
'Y' => 'Y',
'Z' => 'Z',
],
],
),
// Added in MW 1.26
'DisplayFormat' => 'table', // See HTMLForm documentation for available values.
'RLModules' => array(), // Resource loader modules to add to the form display page.
'RLStyleModules' => array(), // Resource loader CSS modules to add to the form display page.
);
possible solutions
1) Writing selection list array keys and values in Hebrew (which might be a bit messy due to LTR-RTL clashings):
'options' => [
'ס' => 'ס',
'ט' => 'ט',
'ז' => 'ז',
],
2) Translating English selection list array keys and values in client side JavaScript by some similar code:
document.getElementById('select').selectedIndex = 0;
document.getElementById('select').value = 'Default';
My desire
I desire an ordinal backend way to do so, and if there is one, than without an extension
In this discussion, a MediaWiki community member recommended using system message transclution but the chapter dealing with it was very unclear to me; I didn't understand what this is about and how can this help in my situation.
My question
What are the possible ways to translate in MediaWiki from "backend", without an extension?
The localisation system is working perfectly fine in the backend (php), as well in the frontend (JavaScript) parts of MediaWiki → staying with it backend is best as it is more minimal.
Assuming you take a backend only approach:
Translation with a predefined string
If your desired translations already exist in MediaWiki (e.g. on another page of form), you can "simply" re-use the key. So, let's assume, your current additional select field definition looks like this:
'Select' => [
'type' => 'select',
'options' => [
'The english message' => 'value'
]
],
Then, you would change it to something like this:
'Select' => [
'type' => 'select',
'options-messages' => [
'the-message-key' => 'test'
]
],
Please consider the changing of options into the options-messages key.
Also: Change the key the-message-key to the message key you want to reuse.
If you know a page where the message/string is used, you can just open that page with the GET option uselang and the value qqx, in order to see the message key. Example: If the string is used on the login page, simply open the login page with https://example.com/wiki/Special:Userlogin?uselang=qqx to show all the message keys used on the page.
However, one warning when doing that: It is mostly discouraged to re-use existing message keys, especially when they're used on other pages. The keys are translated to hundreds of languages with that specific context in mind. That could also mean, that a translation in a specific language does not fit when the string/message is used on the contact page. So I would suggest to use the second option below.
Translation without a predefined string
Usually it will be done by extension which can provide a specific directory where the JSON files with the message key translations are saved. However, as you're "just" customizing an extension, you need a way to put in the translations for your keys.
So, first of all, let's take over the changes from above. Change your select field definition to be something like:
'Select' => [
'type' => 'select',
'options-messages' => [
'my-fancy-key' => 'test'
]
],
Now, two ways to get the key translated:
On-Wiki
By saving the message on-wiki, the messages can also easily being changed simply by editing the respective page in the wiki. In our example, let's translate the key to english and hebrew:
English: Edit the page MediaWiki:My-fancy-key in your wiki and add the desired text.
Hebrew: Edit the page MediaWiki:My-fancy-key/he in your wiki and add the desired text.
As part of the deployed code
We need to register a directory with JSON files for the translations of these messages. We're using the same configuration variable as extensions would use as well, $wgMessagesDirs, even given that we don't create an extension. Add the following line to your LocalSettings.php:
$wgMessagesDirs['ContactPageCustomization'] = __DIR__ . '/customContactPage';
Now, create a directory customContactPage in the root folder of your MediaWiki installation and put in the following file with the following contents:
en.json
{
"my-fancy-key": "Default"
}
If you want to translate to another language, create a new file with the language code you want to translate to. In hebrew it should be he, so let's create a new language file:
he.json
{
"my-fancy-key": "ברירת מחדל"
}
If you then open the contact page, the message key my-fancy-key should be translated to the english Default and the same (at least based on Google Translate) for hebrew. This is a more stable way of adding custom translations, however, you now also need to take care of translating the keys into the languages you want to support on your own as well. If a key is not translated into the selected language of the user, the default language, english, is used.

How to make a custom theme using Laravel and where to store theme data?

I'm building a full website Using Laravel and this problem is facing me , I want to give the user full control to the site appearance and the ability to change website's layout without my help.
But when I'm thinking about someway to do so by database , there are several tables with tens of columns will be added beside the colors and sections that will be added to database every time the user will change something in the layout style.
Is there any other way to store the options of the theme in XML file or anything other than database?
** Note : when I checked the database of Wordpress I hadn't found any thing concerned to themes there , So where Wordpress store theme options?
For your XML-like storage you can use Laravel Config. Let's say you have the file config/templates.php. Inside you can have a lot of stuff like.
return [
'default_template' => 'layouts.templates.default',
'posts' => 'layouts.templates.post',
'footer' => 'layouts.includes.footer',
'options' => [
'full_with' => false,
'has_footer' => true,
'background_color' => '#fff',
'more_keys' => 'key_value'
]
];
Then anywhere in your app you can get the default template like
$view = config('templates.default_template'); //will get
return view($view, compact('params'));
To update a key, like has_footer, you do
config(['templates.options.has_footer' => false]); //will update
This should get you started I think
Simple Example
Let's say user changes default colour from and input and submit the form. You do
public function updateTheme(Request $request) {
if ( $request->has('background_colour') && $request->background_colour != '' ) {
config(['templates.options.background_colour' => $request->background_colour]);
}
}

WordPress user actions log

I want to log every action that the users do. What's the best way to do this and why? Using Custom post types to insert every action as a new post or using user_meta and save details in a multidimensional array? The data would look like this:
array(
array(
'type' => 'comment',
'time' => 1416335275,
'comment_id' => 210
),
array(
'type' => 'post'
'time' => 1416335275,
'post_id' => 450
),
array(
'type' => 'visited'
'visit_type' => 'page',
'time' => 1416335275,
'page_id' => 378
),
// ... etc.
)
I don't ask how to do this, just what do you think is the best way to store that data.
Relevant question: Why in the world would you want to do this?
OK, well to answer this is a generalized sense, Wordpress is a program that interfaces a database with HTTP requests. So you'd have to capture the content of each HTTP request, and probably filter that through requests that contain logged in users versus not logged in users. To be really specific you'd also have to capture the state of the database at each intersection! Sounds like a nightmare.
Probably you have something much more specific in mind than: "I want to log every action that the users do."
The best way to store data relevant to a user, is via the user meta system. For example:
http://codex.wordpress.org/Function_Reference/add_user_meta

Buddypress bp_core_new_nav_item() function not working to create new navigation item under ”my profile” tab

So I’m trying to add a new navigation under the “my profile” tab in buddypress once a user logs in. I created and am using the bp-custom.php file in my wp-content/plugins directory (outside of the buddypress directory) to insert the custom code.
This is the code I have in bp-custom.php file (and that’s all I have!)
<?php
//place for custom buddypress functions
bp_core_new_nav_item(
array(
'name' => 'feedback',
'slug' => 'Feedback'
));
?>
I got the following error in my browser.
————————–
Server error
The website encountered an error while retrieving http://myhostname.com It may be down for maintenance or configured incorrectly
—————————
I am using the frisco for buddypress theme, not sure if this is part of my problem.
What can I do to fix this error? (move bp-custom? misuse of function? theme incompatibility?) I will rate you up if you give me the correct answer. Thanks in advance!
-Alex
Please use this one:
bp_core_new_nav_item( array(
'name' => __( 'My Links', 'bp-my-links' ),
'slug' => 'my-link',
'position' => 80,
'screen_function' => 'bp_my_link_screen_my_links',
'default_subnav_slug' => 'my-link'
) );
Please put this code and see the under my profile tab there it will display the new "My Link" menu.
asked and answered here:
http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/bp_core_new_nav_item-not-working-to-create-new-navigation-item-under-my-profile-tab/

Categories